本地web应用程序不parsinglocalhost

我有一个名为http://localhost.example.com的本地网站,但现在当我尝试在networking浏览器中打开它时,它将我redirect到http://www.example.com 。 这曾经工作过。 我在系统中修改的是AWS CLI和Bitbucket本地configuration的configuration,以便使用两个不同的帐户。 而已。 我相信这些变化是无关紧要的。 不是吗?

我提供的所有信息和文件都来自本地工作站。 我正在使用OS X 10.12(testing版2)。

/ etc / hosts的相关部分是这样的:

127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost 127.0.0.1 localhost.example.com 127.0.0.1 babydiapi.example.com 127.0.0.1 localhost.mi.example.com 127.0.0.1 localhost.qr.example.com 127.0.0.1 localhost.pay.example.com 127.0.0.1 playground.com 127.0.0.1 payments.com 127.0.0.1 localhost.comunidad.example.com 198.58.110.224 web1.example.com 198.58.115.115 web2.example.com 45.56.67.40 web3.example.com 

但是我做ping localhost.example.com我得到这个:

 PING localhost.example.com (104.200.16.137): 56 data bytes 64 bytes from 104.200.16.137: icmp_seq=0 ttl=49 time=166.894 ms 

我试图做ping http://localhost.example.com但它没有奏效:

 ping: cannot resolve http://localhost.example.com: Unknown host 

我想这是一个正常的行为。

哪个是我的应用程序的登台服务器。 显然不是localhost。

我读了一个地方,我应该使用host localhost.example.com ,但我仍然得到这个:

 localhost.example.com has address 104.200.16.137 

我使用Nginx作为我的本地Web服务器,configuration如下所示:

 server { listen 127.0.0.1:80; listen 127.0.0.1:443 ssl; server_name localhost.example.com; server_name_in_redirect off; error_page 404 /www/error/404.html; error_page 503 /www/error/404.html; ssl_certificate /usr/local/etc/nginx/ssl/localhost.crt; ssl_certificate_key /usr/local/etc/nginx/ssl/localhost.key; access_log /usr/local/etc/nginx/logs/www.example.com.access.log; error_log /usr/local/etc/nginx/logs/www.example.com.error.log; location ~ ^/(.*)/$ { rewrite ^/(.*)/$ /$1 permanent; } location ~* ^.+(\.jpg|\.jpeg|\.gif|\.png|\.js|\.ico|\.woff|\.ttf|\.eot|\.css)$ { root /www/www.example.com/webroot; access_log off; expires 365d; } location / { root /var/www/www.example.com/webroot/; index index.php index.html index.htm; if (-f $request_filename) { break; } if (-d $request_filename) { break; } if (-f $request_filename) { break; } # Trigger 503 response on maintenance set $mantenimiento 0; if (-f /var/www/www.example.com/.mantenimiento) { set $mantenimiento 1; } if ($remote_addr = 127.0.0.1) { set $mantenimiento 0; } if ($mantenimiento) { return 503; } if (!-f $request_filename) { rewrite ^/(.+)$ /index.php?url=$1 last; break; } } location ~ .*\.php[345]?$ { set $script $uri; set $path_info ""; if ($uri ~ "^(.+\.php)(/.+)") { set $script $1; set $path_info $2; } include fastcgi_params; fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; fastcgi_param SCRIPT_FILENAME /var/www/www.example.com$fastcgi_script_name; fastcgi_param SCRIPT_NAME $script; fastcgi_param PATH_INFO $path_info; fastcgi_buffer_size 128k; fastcgi_buffers 4 256k; fastcgi_busy_buffers_size 256k; fastcgi_read_timeout 300; } location @error_web { root /var/www/error; index 404.html; } } 

你有什么想法或提示? 我一直在网上查了一个星期,发现没有什么帮助。

我很想为你testing这个,但是我没有OSX。

有一些关于这个问题的讨论。 人们说在主机文件中的格式问题(丢失/缺less/不正确的隐藏字符)可能会导致它被忽略。 看到下面的问题,并向下滚动到答案和评论。

https://apple.stackexchange.com/questions/158117/os-x-10-10-1-etc-hosts-private-etc-hosts-file-is-being-ignored-and-not-resol

你也可以看看这个疯狂。 再次与格式化的主机文件。

https://github.com/devopsgroup-io/vagrant-hostmanager/issues/60

你在用什么编辑器? 你可以使用vi,nano或其他Unix编辑器仔细地重写整个文件吗?

不要使用主机或nslookup,挖等,他们将绕过主机文件和查询DNS服务器。 继续尝试与ping localhost.domain.com直到你得到127.0.0.1

我很好奇你的/ etc / hosts是不是和/ private / etc / hosts一样。 从我的10.11.5机器上,我发现它们应该是一个硬连接(与以下ls -li输出的第一个字段中看到的相同的inode编号:

 Camerons-MacBook-Air:~ cameron$ ls -li /private/etc/hosts /etc/hosts 12484749 -rw-r--r-- 1 root wheel 247 15 Jul 21:01 /etc/hosts 12484749 -rw-r--r-- 1 root wheel 247 15 Jul 21:01 /private/etc/hosts 

这仍然是你的情况吗? / etc / hosts和/ private / etc / hosts是否指向磁盘上的相同文件?

在Linux主机上,我也想知道/etc/nsswitch.conf,但是我看到OS X似乎没有这个function; 我不确定它会使用什么。 该文件控制parsing名称(如用户名或主机名)的查找方法顺序。

干杯,卡梅隆