server_name seems to be ignored in nginx
- by user46171
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;
}
}
}