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

For some reason, any local IP address in the range redirects back to the default 'Welcome to nginx!' page.

From my experience with Apache, only the IP address would resolve back to the apache web server.

How can I make Nginx only act only on the address?



share|improve this question

2 Answers 2

up vote 2 down vote accepted

You have two separate issues - firstly, multiple addresses ( are reserved for loopback - however, that only explains why an address such as will still point at your computer.

The second problem is that NginX, by default, binds to all available addresses. This setting is defined by the listen directive.

You can verify that NginX has, in fact bound to all addresses by looking at netstat -pant | grep nginx, which may show something like:

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0        *                   LISTEN      12534/nginx

Note the under local address, meaning bind to all addresses.

If you change ALL your server blocks to have a listen directive that explicitly specifies the address to which to bind (e.g. listen you should get the following:

Proto Recv-Q Send-Q Local Address               Foreign Address             State       PID/Program name
tcp        0      0      *                   LISTEN      12536/nginx

(Tested with CentOS 6.2, Nginx 1.2, using curl - after making the change, trying to connect to (or any other non address), results in: curl: (7) couldn't connect to host)

Note: you must explicitly set the listen directive on all server blocks, otherwise, NginX will still listen on all addresses. The default listen directive (i.e. when it is omitted) is listen *:80 and NginX will try each available server block and use the 'best match', even if the server_name doesn't match (if you specify a listen ... default then it will use that one).

share|improve this answer
Great answer, thank you! – Ben May 3 '12 at 22:49

Per section (Addressing) of RFC 1122, the entire block is reserved for loopback; you should avoid using bogon IP addresses, especially special-purpose ones as defined in RFC 5735 for some purpose other than private addressing, as the results may be undefined.

share|improve this answer

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.