Site should not be accessed through IP

Hi Guys,

I have my nginx box deployed as a reverse proxy serving almost more than
sites. But when I browse through 1 IP the first site configured gets
accessed. I dont want anyone to access the sites through IP, by using
FQDN sites should be accesible.

So anyone trying to access the site using IP should recieve a host not
or may be error like COnnection reset.

Can we do that in nginx?

Posted at Nginx Forum:,257927,257927#msg-257927

configure a site first, which does the default handling and has no


Am 09.04.2015 um 20:09 schrieb blason [email protected]:

Can we do that in nginx?

Posted at Nginx Forum:,257927,257927#msg-257927

nginx mailing list
[email protected]

Sebastian S.

Host Europe GmbH is a company of HEG

Telefon: +49 2203 1045-7362

You could use an extra host config with a default_server, like so:

server {
listen 80 default_server;
server_name _;
return 444;

You can find this example on

Posted at Nginx Forum:,257927,257928#msg-257928

Hi Finalx,

you mean shall I create the .conf file by name default_server and add up
this there? Or would you please tell me where shoudl I add the above
Sorry I am being novice in nginx just would like to know more
about this.

Posted at Nginx Forum:,257927,257930#msg-257930

If you’re using a 1-config-per-site setup, then yes, you could. It
completely depends on your setup as to where you need to place it.

You can put it in any existing file that already has a server directive
there. Just make sure none of the other server configs/files have the
default_server in their listen directive.

The server name of _ just makes sure it won’t conflict with any existing
name as hostnames are not allowed to have underscores in them.

The default_server is special, it makes sure that any request that does
have a matching name in the rest of the config will end up there. So not
just the IP that you asked for, but also any other website name that is
in the config.

The 444 status code is just to return a “no response” kinda thing. If
want you can even have a default site there, telling users there is no
at that address with a fancy text and/or logo instead.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs