Ubuntu + Nginx 127.0.0.1的作品,但本地主机不

这个很奇怪,因为我没有任何错误信息。

我有一个非常基本的默认文件:

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; allow 127.0.0.1; deny all; } location /images { root /usr/share; autoindex off; } 

现在,在shell中,

 ping localhost 

很好。

但是,在任何浏览器中,都会显示错误。 例如,Chrome说:“糟糕!Google Chrome无法find本地主机”。

另一方面127.0.0.1在浏览器中工作。

也许你知道我应该在哪里检查错误? / var / log和其他文件都不干净….

首先, ping与NGINX完全相关,你可以ping任何将响应ping请求的服务器,而不pipe服务在运行。

检查;

curl -I -v http://127.0.0.1/ – 将查看该网站是否可以通过本地地址访问

curl -I -v http://localhost/ – 将查看本地主机名是否可访问该站点

curl -I -v http://serverhostname/ – 将查看该服务器主机名是否可以访问该站点

nslookup localhost – 确保“localhost”parsing为127.0.0.1

张贴的输出,如果你仍然有问题,我们可以给你更多的指导

感谢大家! 在nslookup的行为是不相关的,谢谢@Mark! 所以我试了

 sudo ping localhost 

并得到了正确的答案。

最后chmod'ed / etc / hosts到644,现在一切正常。 虽然,不知道是否644是最好的事情。

另一件事,我不知道为什么最初在/ etc / hosts上的权限是

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

但现在这是无关紧要的。