this one is weird, because I don't have any error messages.

I have a very basic default file:

server {
    #listen   80; ## listen for ipv4; this line is default and implied
    #listen   [::]:80 default ipv6only=on; ## listen for ipv6

    root /var/www;
    index index.html index.htm index.php;

    # Make site accessible from http://localhost/
    server_name localhost;

    access_log      /var/log/nginx/default.access_log;
    error_log       /var/log/nginx/default.error_log warn;

    location / {
            # First attempt to serve request as file, then
            # as directory, then fall back to index.html
            try_files $uri $uri/ /index.html;

    location /doc {
            root /usr/share;
            autoindex on;
            deny all;

    location /images {
            root /usr/share;
            autoindex off;

Now, in shell,

ping localhost 

is fine.

However, in any browser, it displays an error. Chrome, for instance says: "Oops! Google Chrome could not find localhost". on the other hand works in browsers.

Maybe you know where should I check for errors? Nothing in /var/log and other files are clean....

  • Does telnet localhost 80 from a shell work? How about curl http://localhost? – Andy Smith Dec 2 '11 at 11:15
  • Another thing that can trip this up is if you have an ipv6 address. On OSX 8 localhost is routed to the ipv6 address. Compiling Nginx with --with-ipv6 and adding the the this listen directive listen [::1]:80 will work too. – Justin May 19 '13 at 3:50

Firstly, ping is completely relevant to NGINX, you can ping any server that will respond to ping requests regardless of the services running.


curl -I -v - Will see if the site is accessible by local address

curl -I -v http://localhost/ - Will see if the site is accessible by local hostname

curl -I -v http://serverhostname/ - Will see if the site is accessible by servers hostname

nslookup localhost - Make sure 'localhost' is resolving to

Post the output of that and if you're still having issues we can give you more guidance

  • sam, thank you! Yep! curl was fine - it gave 200 OK answer for localhost and But: root@valk-pc:~# nslookup localhost Server: Address: Non-authoritative answer: *** Can't find localhost: No answer This is the address of the router. But my /etc/hosts file contains localhost.localdomain localhost From the other place, I read that hosts file is irrelevant though. – valk Dec 2 '11 at 11:43
  • @valk That would be your issue, do you have an entry for localhost in /etc/hosts? – Smudge Dec 2 '11 at 11:46
  • I do have. I edited my previous reply. /etc/hosts is: localhost.localdomain localhost valk-pc # The following lines are desirable for IPv6 capable hosts ::1 ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters ff02::3 ip6-allhosts – valk Dec 2 '11 at 11:53
  • 1
    nslookup does not use /etc/hosts file, it rather uses the nameservers listed in the /etc/resolv.conf file. (hence people tend to add a localhost entry to their dns entry's) – Mark Dec 2 '11 at 12:48

Thanks everyone! In deed nslookup isn't relevant, thanks @Mark! So I tried

sudo ping localhost 

and got a correct answer.

Finally chmod'ed /etc/hosts to 644 and now everything is working. Although, not sure whether 644 is the best thing to chmod to.

Another thing, I have no idea why initially the permissions on /etc/hosts were

-rw------- 1 root root 278 2011-12-02 22:52 /etc/hosts

but now it's kind of irrelevant.

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.