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.

This is my config file for nginx to allow it to respond only to domain1.com, and not domain2.com

server {
    server_name  .domain1.com;
    root /var/www/;

    #charset koi8-r;

    #access_log  logs/host.access.log  main;

    location / {
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header Host $http_host;
        proxy_set_header X-NginX-Proxy true;
        proxy_pass http://127.0.0.1:3000;
        proxy_redirect off;
    }
}

However this is still listening on domain2.com. What am I missing here? Any help is appreciated.

share|improve this question
add comment

2 Answers

up vote 1 down vote accepted

This is not possible, at least not this way. If the server receives a request with a Host header for a domain that is configured in no server_name statement, it will fall back to a default server, even if the server_name does not match.

See the documentation for more info on the fallback order.

share|improve this answer
add comment

Yep SvenW is correct, you need to set up a default vhost, possibly just set it to return a 404 if that's desired behaviour, or some sort of holding page.

share|improve this answer
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.