nginx configuration - make accessible from outside localhost

I have this in my nginx.conf

server {
      listen 80;
      server_name localhost;
      root /opt/myapp/public;
      passenger_enabled on;
}

The problem is I can access the webapp from the computer on which it's running, but not from any other computer in the network. Any ideas?

Running on CentOS 5.6


Solution 1:

'server_name localhost' makes nginx require the Host header to be 'localhost', ie require that the client is trying to reach it using 'http://localhost' and thus only work on localhost itself :-).

Either do not enter a server_name, or use one that the other hosts will recognize it with (fqdn, IP etc).

http://wiki.nginx.org/VirtualHostExample

Solution 2:

It should be listening on all interfaces with that config, you can check if it's indeed listening on all interfaces with the following command

netstat -aln | grep 80

The result should look like this (Taken from one of my servers)

tcp    0      0 0.0.0.0:80           0.0.0.0:*            LISTEN

If that matches, you should check if you have a firewall enabled on the server, if so you need to open TCP port 80 on it.