将www.domain.com重定向到domain.com

发布于 2025-01-19 18:38:56 字数 1198 浏览 0 评论 0原文

我通过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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遮了一弯 2025-01-26 18:38:56

考虑将此配置部分移动到配置文件的最开头

server {
    listen 80;
    server_name www.domain.com;
    return 301 $scheme://domain.com$request_uri;
}

此外,可能存在一些缓存,甚至是损坏的缓存,因此您可能需要时间让它们过期

Consider moving this config part to the very beginning of your config file

server {
    listen 80;
    server_name www.domain.com;
    return 301 $scheme://domain.com$request_uri;
}

Also there might exist some caches, even broken ones, so you might need time for them to expire

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文