server_name 似乎在 nginx 中被忽略

server_name 似乎在 nginx 中被忽略

我在 nginx.conf 中设置了两个域。两个域都使用 SSL 和自己的证书,并代理到 Apache。

但是第二个域被完全忽略,并且 nginx 始终解析为第一个域。我看不出此配置存在什么问题,因为在每种情况下都正确设置了 server_name(据我所知):

http {
    include       mime.types;
    default_type  application/octet-stream;

    keepalive_timeout  65;

    upstream site {
        # real IP addresses masked
        server xx.xxx.x.xxx;
        server xx.xxx.x.xxx;
    }


    server {
        # this domain always works
        listen       443;
        server_name  *.first-site.com;

        ssl                  on;
        ssl_certificate      /var/ssl/first-site.crt;
        ssl_certificate_key  /var/ssl/first-site.key;

        location / {
            access_log off;
            proxy_connect_timeout 15;
            proxy_next_upstream error;
            proxy_pass http://site;
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Protocol https;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect off;
        }

    }

    server {
        # this domain is ignored, always resolves to first-site.com
        listen       443;
        server_name  *.second-site.com;

        ssl                  on;
        ssl_certificate      /var/ssl/second-site.crt;
        ssl_certificate_key  /var/ssl/second-site.key;

        location / {
            access_log off;
            proxy_connect_timeout 15;
            proxy_next_upstream error;
            proxy_pass http://site;
            proxy_set_header Host $http_host;
            proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-Protocol https;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_redirect off;
        }

    }

}

答案1

您需要调整您的 Listen 指令来监听 IP 和端口号。

Listen 1.2.3.4:443

目前,SSL 需要有单独的 IP(或单独的端口)

相关内容