Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 is configured for, I want to allow a request for but deny a request for

share|improve this question

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;

server {
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.