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

I'm using nginx. If my ip numbers are and, how can I configure it to block requests for the ip numbers and only allow domains. If site1.com is configured for, I want to allow a request for site1.com but deny a request for

share|improve this question

1 Answer 1

You can create a default catch-all virtual host to serve requests for non-configured domains and do whatever you want with these requests. Something like this:

# Default vhost
server {
    listen default_server;
    server_name _;

    location / {
        return 404;

# site1.com
server {
    server_name site1.com;
share|improve this answer
I want to use the ip for multiple domains, so I'm using default_server already for valid sites. I'm thinking I need to regex match on host name and if it is an ip address, deny. –  Poe Oct 7 '11 at 13:48
Nope, just define your valid domains in server_name in the appropriate server container - you don't need to set default_server for them. –  Vladimir Blaskov Oct 7 '11 at 20:21

Your Answer


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.