将www.domain.com重定向到domain.com
我通过SEO工具和Google工具在Django网站的爬网上获得了重复的URL。我想抛弃 www.domain.com 完全并将所有流量重定向到
下面的domain.com。 Cerbot添加了其HTTPS信息。好奇我在这里做错了什么。
server {
server_name domain.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /root/domain/domain-django;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.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 {
server_name www.domain.com;
return 301 $scheme://domain.com$request_uri;
}
server {
if ($host = domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name domain.com;
return 404; # managed by Certbotserver
}
I am getting duplicate URLs on crawls of my Django site via my SEO tools and via Google tools. I want to ditch www.domain.com completely and redirect all traffic to domain.com
Below is my NGINX conf. Cerbot has added its https info. Curious what I’m doing wrong here.
server {
server_name domain.com;
location = /favicon.ico { access_log off; log_not_found off; }
location /static/ {
root /root/domain/domain-django;
}
location / {
include proxy_params;
proxy_pass http://unix:/run/gunicorn.sock;
}
listen 443 ssl; # managed by Certbot
ssl_certificate /etc/letsencrypt/live/domain.com/fullchain.pem; # managed by Certbot
ssl_certificate_key /etc/letsencrypt/live/domain.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 {
server_name www.domain.com;
return 301 $scheme://domain.com$request_uri;
}
server {
if ($host = domain.com) {
return 301 https://$host$request_uri;
} # managed by Certbot
listen 80;
server_name domain.com;
return 404; # managed by Certbotserver
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
考虑将此配置部分移动到配置文件的最开头
此外,可能存在一些缓存,甚至是损坏的缓存,因此您可能需要时间让它们过期
Consider moving this config part to the very beginning of your config file
Also there might exist some caches, even broken ones, so you might need time for them to expire