Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

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

    }

}
share|improve this question
add comment

1 Answer

You need to adjust your Listen directive to Listen to an IP and port number.

Listen 1.2.3.4:443

Currently, SSL needs to have separate IPs (or separate ports)

share|improve this answer
    
I had to do a combination of two things: 1, add the IP address to the port as described here. 2, use the default_server parameter on one of the servers to prevent the other ones from automatically handling requests that should have been explicitly handled by only a single server { } block. Thank you for this. –  Bryson Jan 27 at 15:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.