[英]Multiple domains with Nginx (Reverse Proxy)
I have nginx up and running on my debian server with the following configuration : 我已经使用以下配置在我的debian服务器上运行了nginx:
root@serverAUS:/var/log/nginx# nginx -V
nginx version: nginx/1.10.3
built with OpenSSL 1.1.0f 25 May 2017
TLS SNI support enabled
configure arguments: --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-2tpxfc/nginx-1.10.3=. -fstack-protector-strong -Wformat -Werror=format-security -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-z,relro -Wl,-z,now' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-pcre-jit --with-ipv6 --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_geoip_module=dynamic --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-auth-pam --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-dav-ext-module --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-echo --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/nginx-upstream-fair --add-dynamic-module=/build/nginx-2tpxfc/nginx-1.10.3/debian/modules/ngx_http_substitutions_filter_module
My nginx configuration looks like to : 我的nginx配置看起来像:
server {
listen 80;
# first domain
server_name firstsubdomain.domain.tld;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
location / {
proxy_pass http://192.168.XX.YY;
}
}
I would like to know if we can set up another subdomain for the specified virtual host. 我想知道是否可以为指定的虚拟主机设置另一个子域。
server {
listen 80;
# first domain
server_name firstsubdomain.domain.tld;
access_log /var/log/nginx/access.log;
error_log /var/log/nginx/error.log;
# another subodmain
servername secondsubdomain.domain.tld;
location / {
proxy_pass http://192.168.XX.YY;
}
}
It doesn't work, I don't understand. 它不起作用,我不明白。 I tried to change my Mac Address and my IP Address but it still doesn't work...
我试图更改我的Mac地址和IP地址,但仍然无法正常工作...
root@serverAUS:~# service nginx restart
Job for nginx.service failed because the control process exited with error code.
See "systemctl status nginx.service" and "journalctl -xe" for details.
Gabriel Tretyakova 加布里埃尔·特列季科娃(Gabriel Tretyakova)
Put both server names on the same block, make sure server_name has an underscore: 将两个服务器名称放在同一块上,确保server_name下划线:
server_name
firstsubdomain.domain.tld
secondsubdomain.domain.tld;
You can check the following configuration. 您可以检查以下配置。 Here, three subdomain www , admin and api are hosted on the same server (DigitalOcean - Ubuntu).
在这里,三个子域www , admin和api托管在同一服务器(DigitalOcean-Ubuntu)上。 All the three subdomains point to different directories.
这三个子域都指向不同的目录。
# http://www.example.com
server {
charset utf-8;
client_max_body_size 128M;
sendfile off;
server_name www.example.com;
root /var/www/html/example/frontend/web;
index index.php;
access_log /var/log/nginx/www.example.com-access.log;
error_log /var/log/nginx/www.example.com-error.log;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
try_files $uri =404;
}
location ~ /\.(ht|svn|git) {
deny all;
}
}
# http://admin.example.com
server {
charset utf-8;
client_max_body_size 128M;
sendfile off;
server_name admin.example.com;
root /var/www/html/example/backend/web;
index index.php;
access_log /var/log/nginx/admin.example.com-access.log;
error_log /var/log/nginx/admin.example.com-error.log;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
try_files $uri =404;
}
location ~ /\.(ht|svn|git) {
deny all;
}
}
# http://api.example.com
server {
charset utf-8;
client_max_body_size 128M;
sendfile off;
server_name api.example.com;
root /var/www/html/example/api/web;
index index.php;
access_log /var/log/nginx/api.example.com-access.log;
error_log /var/log/nginx/api.example.com-error.log;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
try_files $uri =404;
}
location ~ /\.(ht|svn|git) {
deny all;
}
}
# http://api.example.com
server {
charset utf-8;
client_max_body_size 128M;
sendfile off;
server_name cdn.example.com;
root /var/www/html/cdn;
index index.php;
access_log /var/log/nginx/cdn.example.com-access.log;
error_log /var/log/nginx/cdn.example.com-error.log;
location / {
try_files $uri $uri/ /index.php$is_args$args;
}
location ~ \.php$ {
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
fastcgi_pass unix:/run/php/php7.0-fpm.sock;
try_files $uri =404;
}
location ~ /\.(ht|svn|git) {
deny all;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.