2

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

1 Answer 1

3

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 1.2.3.4:80 default_server;
    server_name _;

    location / {
        return 404;
    }
}

# site1.com
server {
    listen 1.2.3.4:80;
    server_name site1.com;
    ...
}
2
  • 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, 2011 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. Oct 7, 2011 at 20:21

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .