server_name seems to be ignored in nginx

Posted by user46171 on Server Fault See other posts from Server Fault or by user46171
Published on 2010-06-18T15:37:12Z Indexed on 2010/06/18 15:43 UTC
Read the original article Hit count: 227

Filed under:
|

I have two domains set up in nginx.conf. Both are using SSL with their own certificates, and proxy to Apache.

However the second domain is completely ignored, and nginx always resolves to the first domain. I can't see what in the issue is with this configuration, having set the server_name in each case correctly (as far as I can see):

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;
        }

    }

}

© Server Fault or respective owner

Related posts about ssl

Related posts about nginx