nginx:[警告]服务器名称冲突“;www.site.com“;在0.0.0.0:443/0.0.0.0:80上,忽略

nginx:[警告]服务器名称冲突“;www.site.com“;在0.0.0.0:443/0.0.0.0:80上,忽略,nginx,Nginx,在certbot autorenewal上运行试运行时,我收到以下警告: Saving debug log to /var/log/letsencrypt/letsencrypt.log - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - Processing /etc/letsencrypt/renewal/example.com.conf - - - - - - - - - - -

在certbot autorenewal上运行试运行时,我收到以下警告:

Saving debug log to /var/log/letsencrypt/letsencrypt.log

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Processing /etc/letsencrypt/renewal/example.com.conf
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Cert not due for renewal, but simulating renewal for dry run
Plugins selected: Authenticator nginx, Installer nginx
Renewing an existing certificate
Performing the following challenges:
http-01 challenge for example.com
http-01 challenge for www.example.com
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:443, ignored
Waiting for verification...
Cleaning up challenges
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:80, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "example.com" on 0.0.0.0:443, ignored
nginx: [warn] conflicting server name "www.example.com" on 0.0.0.0:443, ignored

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
new certificate deployed with reload of nginx server; fullchain is
/etc/letsencrypt/live/example.com/fullchain.pem
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates below have not been saved.)

Congratulations, all renewals succeeded. The following certs have been renewed:
  /etc/letsencrypt/live/example.com/fullchain.pem (success)
** DRY RUN: simulating 'certbot renew' close to cert expiry
**          (The test certificates above have not been saved.)
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Nginx配置的规则应该1)将所有http重定向到https,2)将所有非www重定向到www。它做到了这一点,这很好,但有一个警告表明它可以改进

我当前的配置可能很明显出了什么问题,但我找不到如何在修复它的同时保持一切正常工作。这是我的配置文件(
/etc/nginx/sites enabled/example.com
):


简短回答:

第三个服务器块应该是:

server {
    listen 443 ssl;
    server_name example.com;
    ssl_certificate ... etc etc 
    return 301 https://www.example.com$request_uri;
}
解释

您有两个服务器名和两个端口,因此有4种组合

  • example.com:80
  • example.com:443
其中的每一个都应该在服务器块上处理一次,而且只能处理一次。然而

nginx:[警告]0.0.0.0:80上的服务器名称“www.example.com”冲突,已忽略

  • 它在第一个块中声明一次,在第三个块中声明两次
nginx:[警告]0.0.0.0:80上的服务器名称“example.com”冲突,已忽略

  • 第一个街区一次,第三个街区两次
nginx:[警告]0.0.0.0:443上的服务器名称“www.example.com”冲突,已忽略

  • 第二个街区一次,第三个街区两次
nginx:[警告]0.0.0.0:443上的服务器名称“example.com”冲突,已忽略

  • 第三个街区有两次
重定向流的一般逻辑应该是:

# handle example.com:80
# handle www.example.com:80
server {
    listen 80;

    server_name www.example.com example.com;
    return 301 https://www.example.com$request_uri;
}

# handle  example.com:443
server {
    listen 443 ssl; # managed by Certbot
    ssl_certificate ... etc etc 

    server_name example.com;
    return 301 https://www.example.com$request_uri;
}

# handle www.example.com:443
 server {
    listen 443 ssl; # managed by Certbot
    ssl_certificate ... etc etc 

    server_name www.example.com;
    root /var/www/example/code/public;
 }

请注意,即使将被立即重定向,您仍然需要非www主机的证书。

简短回答:

第三个服务器块应该是:

server {
    listen 443 ssl;
    server_name example.com;
    ssl_certificate ... etc etc 
    return 301 https://www.example.com$request_uri;
}
解释

您有两个服务器名和两个端口,因此有4种组合

  • example.com:80
  • example.com:443
其中的每一个都应该在服务器块上处理一次,而且只能处理一次。然而

nginx:[警告]0.0.0.0:80上的服务器名称“www.example.com”冲突,已忽略

  • 它在第一个块中声明一次,在第三个块中声明两次
nginx:[警告]0.0.0.0:80上的服务器名称“example.com”冲突,已忽略

  • 第一个街区一次,第三个街区两次
nginx:[警告]0.0.0.0:443上的服务器名称“www.example.com”冲突,已忽略

  • 第二个街区一次,第三个街区两次
nginx:[警告]0.0.0.0:443上的服务器名称“example.com”冲突,已忽略

  • 第三个街区有两次
重定向流的一般逻辑应该是:

# handle example.com:80
# handle www.example.com:80
server {
    listen 80;

    server_name www.example.com example.com;
    return 301 https://www.example.com$request_uri;
}

# handle  example.com:443
server {
    listen 443 ssl; # managed by Certbot
    ssl_certificate ... etc etc 

    server_name example.com;
    return 301 https://www.example.com$request_uri;
}

# handle www.example.com:443
 server {
    listen 443 ssl; # managed by Certbot
    ssl_certificate ... etc etc 

    server_name www.example.com;
    root /var/www/example/code/public;
 }

请注意,即使会立即重定向,您仍然需要非www主机的证书。

谢谢您的详细解释,我会尝试并让您不断更新!我试过了,但警告仍然存在。。。我重新启动了nginx和passenger(以防万一),但它仍然是一样的。我将更新我的原始帖子以反映我当前的Nginx配置。你知道为什么它会继续显示这些警告吗?在你的问题中,你是否也更新了警告消息?您确定没有其他启用的站点提到www.example.com或example.com吗?请确保粘贴当前vhost文件。记住,当你告诉certbot将http重定向到HttpSac时,certbot会改变它。实际上,警告会重复多次(25-30次,在挑战之前和之后-我将使用当前输出进行更新)。我帖子中的配置文件是当前的(根据您的建议进行了修改)。感谢您的详细解释,我会尝试一下,让您不断更新!我试过了,但警告仍然存在。。。我重新启动了nginx和passenger(以防万一),但它仍然是一样的。我将更新我的原始帖子以反映我当前的Nginx配置。你知道为什么它会继续显示这些警告吗?在你的问题中,你是否也更新了警告消息?您确定没有其他启用的站点提到www.example.com或example.com吗?请确保粘贴当前vhost文件。记住,当你告诉certbot将http重定向到HttpSac时,certbot会改变它。实际上,警告会重复多次(25-30次,在挑战之前和之后-我将使用当前输出进行更新)。我帖子中的配置文件是当前的(根据您的建议修改)。