NGINX-0.0.0.0:80 上冲突的服务器名称“www.foo.com”,被忽略

NGINX-0.0.0.0:80 上冲突的服务器名称“www.foo.com”,被忽略

我不明白为什么会nginx引发错误conflicting server name

我的项目在两个域上运行 -foo.combar.com。设置完成后nginx,我安装了let's encrypt证书,该证书在 中添加了一个服务器块sites-available/myproject

然后我尝试设置从www.foo.comwww.bar.com到的重定向foo.combar.com但这两个域不起作用。

sudo nginx -t
nginx: [warn] conflicting server name "www.foo.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.bar.com" 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

同样的节目error.log

这是sites-available/myproject

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

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

server {
    server_name foo.com bar.com;

    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/foo.com/fullchain.pem; # managed by Certbot
    ssl_certificate_key /etc/letsencrypt/live/foo.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 = bar.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    if ($host = foo.com) {
        return 301 https://$host$request_uri;
    } # managed by Certbot


    listen 80;
    server_name 178.128.xxx.xxx foo.com bar.com;
    return 404; # managed by Certbot




}

所以我想要的是将所有文件重定向wwwnon-www安全的目录。你知道问题出在哪里吗?

相关内容