Nginx - 0.0.0.0:80 上的服务器名称冲突

Nginx - 0.0.0.0:80 上的服务器名称冲突

不明白为什么nginx不会将wwwurl 重定向到non-www.

我希望所有www网址都重定向到non-www.

Nginxerror.log显示这些消息:

2019/05/28 17:45:07 [warn] 21670#21670: conflicting server name "www.my-first-domain.at" on 0.0.0.0:80, ignored

可用站点

server {
    listen 80;
    server_name www.my-first-domain.at;
    return 301 $scheme://my-first-domain.at$request_uri;
}

server {
    listen 80;
    server_name www.my-second-domain.at;
    return 301 $scheme://my-second-domain.at$request_uri;
}

server {
    server_name my-first-domain.at my-second-domain.at;

    location = /favicon.ico { access_log off; log_not_found off; }
    location /static/ {
        root /home/futilestudio/myproject;
    }

    location / {
        include proxy_params;
        proxy_pass http://unix:/run/gunicorn.sock;
    }

    listen 443 ssl; # managed by Certbot
    ssl_certificate /etc/letsencrypt/live/my-first-domain.at/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/my-first-domain.at/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 = my-second-domain.at) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = my-first-domain.at) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name 178.128.xxx.xxx my-first-domain.at my-second-domain.at;
    return 404; # managed by Certbot

}

非 www 域可以正常工作。你知道问题出在哪里吗?

编辑

(venv) futilestudio@Brennholz-2:~/myproject sudo nginx -t
nginx: [warn] conflicting server name "www.my-first-domain.at" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.my-second-domain.at" on 0.0.0.0:80, ignored
nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
nginx: configuration file /etc/nginx/nginx.conf test is successful

相关内容