.com
我最近更新了我的配置,因为我的所有重定向中都缺少一个(哎呀),所以我更新了我的配置文件并运行sudo systemctl restart nginx
,发现它仍然重定向到坏域,运行sudo reboot
,仍然没有看到任何变化。然后我等了一个多小时,希望 DNS 能够传播,以防这是问题所在,但事实并非如此。
旧配置
server {
server_name domainA.com www.domainA.com
domainB.com www.domainB.com;
if ($host = www.domainB.com) {
return 301 https://domainA$request_uri;
} # managed by Certbot
if ($host = domainB.com) {
return 301 https://domainA$request_uri;
} # managed by Certbot
if ($host = www.domainA.com) {
return 301 https://domainA$request_uri;
} # managed by Certbot
location = /favicon.png { access_log off; log_not_found off; }
location /media {
alias /home/matt/project-dir/media;
}
location /static {
alias /home/matt/project-dir/static;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domainB.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domainB.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.domainB.com) {
return 301 https://domainA$request_uri;
} # managed by Certbot
if ($host = domainB.com) {
return 301 https://domainA$request_uri;
} # managed by Certbot
if ($host = www.domainA.com) {
return 301 https://domainA$request_uri;
} # managed by Certbot
if ($host = domainA.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name domainA.com www.domainA.com
domainB.com www.domainB.com;
listen 80;
return 404; # managed by Certbot
}
新配置
唯一不同之处:return 301 https://domainA$request_uri;
→return 301 https://domainA.com$request_uri;
重复六次
server {
server_name domainA.com www.domainA.com
domainB.com www.domainB.com;
if ($host = www.domainB.com) {
return 301 https://domainA.com$request_uri;
} # managed by Certbot
if ($host = domainB.com) {
return 301 https://domainA.com$request_uri;
} # managed by Certbot
if ($host = www.domainA.com) {
return 301 https://domainA.com$request_uri;
} # managed by Certbot
location = /favicon.png { access_log off; log_not_found off; }
location /media {
alias /home/matt/project-dir/media;
}
location /static {
alias /home/matt/project-dir/static;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domainB.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domainB.com/privkey.pem; # managed by Certbot
include /etc/letsencrypt/options-ssl-nginx.conf; # managed by Certbot
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem; # managed by Certbot
}
server {
if ($host = www.domainB.com) {
return 301 https://domainA.com$request_uri;
} # managed by Certbot
if ($host = domainB.com) {
return 301 https://domainA.com$request_uri;
} # managed by Certbot
if ($host = www.domainA.com) {
return 301 https://domainA.com$request_uri;
} # managed by Certbot
if ($host = domainA.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
server_name domainA.com www.domainA.com
domainB.com www.domainB.com;
listen 80;
return 404; # managed by Certbot
}
我可以做出哪些实际会反映出来的改变?
编辑1:添加/etc/nginx
目录列表
# tree /etc/nginx
/etc/nginx
├── conf.d
├── fastcgi.conf
├── fastcgi_params
├── koi-utf
├── koi-win
├── mime.types
├── modules-available
├── modules-enabled
│ ├── 50-mod-http-auth-pam.conf -> /usr/share/nginx/modules-available/mod-http-auth-pam.conf
│ ├── 50-mod-http-dav-ext.conf -> /usr/share/nginx/modules-available/mod-http-dav-ext.conf
│ ├── 50-mod-http-echo.conf -> /usr/share/nginx/modules-available/mod-http-echo.conf
│ ├── 50-mod-http-geoip.conf -> /usr/share/nginx/modules-available/mod-http-geoip.conf
│ ├── 50-mod-http-image-filter.conf -> /usr/share/nginx/modules-available/mod-http-image-filter.conf
│ ├── 50-mod-http-subs-filter.conf -> /usr/share/nginx/modules-available/mod-http-subs-filter.conf
│ ├── 50-mod-http-upstream-fair.conf -> /usr/share/nginx/modules-available/mod-http-upstream-fair.conf
│ ├── 50-mod-http-xslt-filter.conf -> /usr/share/nginx/modules-available/mod-http-xslt-filter.conf
│ ├── 50-mod-mail.conf -> /usr/share/nginx/modules-available/mod-mail.conf
│ └── 50-mod-stream.conf -> /usr/share/nginx/modules-available/mod-stream.conf
├── nginx.conf
├── proxy_params
├── scgi_params
├── sites-available
│ ├── production
│ └── staging
├── sites-enabled
│ └── production -> /etc/nginx/sites-available/production
├── snippets
│ ├── fastcgi-php.conf
│ └── snakeoil.conf
├── uwsgi_params
└── win-utf
答案1
我刚刚和 Namecheap 的代表聊完。结果发现是 DNS 尚未传播,而我之前错误地排除了这种可能性。您可能已经知道,这可能需要长达 24 甚至 48 小时。与最近没有连接到我的网站的人交谈让我能够让一切正常运行。
答案2
我看不出 DNS 和 Nginx 重定向问题之间有什么关系。不过,当你调试重定向时,尽量不要使用 Firefox、Chrome 等桌面 Web 浏览器,因为它们会缓存重定向并欺骗你。
最好使用 curl 测试重定向:
curl -I https://www.yoursite.com
如果您没有 curl,那么您最好在每次测试之间关闭网络浏览器。