我有两个域在同一台服务器上托pipe。 在DNSlogging中我有通配符(*)两个域的logging指向服务器。
所以我期待xyz.domain1.comparsing到domain1.com和xyz.domain2.com到domain2.com 。
不过目前除了domain2.com上的www子域名之外的所有内容都被redirect到了domain1.com 。
我有两个相同的nginxconfiguration域,所以我不明白是什么原因造成的。 这是我的nginxconfiguration看起来像 –
user nginx; worker_processes 1; error_log /var/log/nginx/error.log warn; pid /var/run/nginx.pid; events { worker_connections 1024; } http { include /etc/nginx/mime.types; default_type application/octet-stream; log_format main '$remote_addr - $remote_user [$time_local] "$request" ' '$status $body_bytes_sent "$http_referer" ' '"$http_user_agent" "$http_x_forwarded_for"'; access_log /dev/stdout main; sendfile on; keepalive_timeout 65; # Listen for non-HTTPS requests and redirect them to HTTPS server { server_name www.domain1.com domain1.com; return 301 https://domain1.com$request_uri; } # Listen for www requests with HTTPS and redirect them to non www site server { listen 443 ssl; server_name www.domain1.com; ssl_certificate /etc/letsencrypt/live/www.domain1.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/www.domain1.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; return 301 https://domain1.com$request_uri; } # Listen for non-www HTTPS requests and serve the app server { listen 443 ssl; #add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; server_name domain1.com api.domain1.com; ssl_certificate /etc/letsencrypt/live/www.domain1.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/www.domain1.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; location ^~ /.well-known/ { root /usr/share/nginx/html; allow all; } location / { root /var/www/domain1; } } # Listen for non-HTTPS requests and redirect them to HTTPS server { server_name www.domain2.com domain2.com; return 301 https://domain2.com$request_uri; } # Listen for www requests with HTTPS and redirect them to non www site server { listen 443 ssl; server_name www.domain2.com; ssl_certificate /etc/letsencrypt/live/www.domain2.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/www.domain2.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; return 301 https://domain2.com$request_uri; } # Listen for non-www HTTPS requests and serve the app server { listen 443 ssl; #add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always; server_name domain2.com; ssl_certificate /etc/letsencrypt/live/www.domain2.com/fullchain.pem; ssl_certificate_key /etc/letsencrypt/live/www.domain2.com/privkey.pem; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_ciphers HIGH:!aNULL:!MD5; location ^~ /.well-known/ { root /usr/share/nginx/html; allow all; } location / { root /var/www/domain2; } } }
我如何保持域独立,使每个子域名redirect到正确的域名?
您必须为每个域包含通配符server_name条目以select要redirect到的域。 否则未知的server_names将被分派到第一个条目(在这种情况下,redirect到domain1.com)。
将*.domain2.com添加到server_name www.domain2.com的行,它应该正确拆分domain2.com子域名。