5

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

14

'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

3
  • Thanks for pointing that out. That does clear some things. Seems though that my problem was actually because of CentOS. The firewall was blocking everything, nginx was working fine – andrew Jun 11 '11 at 10:59
  • Adding a comment since this applied to me. I also did not forward all the ports in my router. This is not nginx related but was one of the reasons I didn't see my webserver from a different computer in the same network. – Mathias Apr 19 '17 at 17:01
  • just recording that @andrew's comment helped me, it appears that firewalld (the default firewall for centos) blocks most, if not all ports, by default unless otherwise configured. In my case, albeit accidently, installed firewalld and my machine was unreachable from anywhere but the machine itself. So i could access my ip address on a browser on my machine=, but any other machine on the same network i got an "unreachable" error – Fuseteam Feb 21 '20 at 11:21
3

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.