php 127.0.0.1 可访问/工作但本地主机不可访问/不工作
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/20345132/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
127.0.0.1 is accessible/working but localhost not accessible/ not working
提问by JOE
I am using wamp for few years and i upgraded to windows 8 few months before, my wamp working smoothly up to yesterday. But now it can't be accessed using localhost. but when i trying 127.0.0.1 instead it works smoothly. I changed ::1 localhostto 127.0.0.1 localhostin host file. which where the solution suggested for this problem in most websites. But unfortunately its not work for me. When i ping localhostits showing replay from ::1: time<1ms. And There is no software's using port 80 i already checked it. please help to solve this.
我已经使用 wamp 几年了,几个月前我升级到了 Windows 8,直到昨天我的 wamp 工作顺利。但是现在无法使用本地主机访问它。但是当我尝试 127.0.0.1 时,它运行顺利。我在主机文件中将::1 localhost更改为127.0.0.1 localhost。在大多数网站中,解决方案针对此问题提出了建议。但不幸的是它对我不起作用。当我ping localhost它显示从 ::1: time<1ms 重播。并且没有软件使用端口 80 我已经检查过了。请帮助解决这个问题。
回答by user2310209
Edit
编辑
%SystemRoot%\system32\drivers\etc\hosts
and replace
并替换
::1 localhost
with
和
127.0.0.1 localhost
Save and restart apache. Hope it will work .
保存并重启apache。希望它会起作用。
回答by vahnevileyes
For DNS problem:
对于 DNS 问题:
ipconfig /flushdns
ipconfig /flushdns
ipconfig /registerdns
ipconfig /registerdns
or rather backup the code and reinstall the wamp server.
或者更确切地说,备份代码并重新安装 wamp 服务器。
Much faster solution however remember you're wamp settings.
更快的解决方案但是请记住您是 wamp 设置。
回答by nl-x
Add 127.0.0.1 localhostto your hosts file.
添加127.0.0.1 localhost到您的主机文件。
If there is a #(comment sign) in front of it, remove it.
如果#前面有(注释符号),请将其删除。
Remove other instances of localhost, or place a #in front of those other instances.
删除 localhost 的其他实例,或#在这些其他实例前面放置一个。
Your hosts file is usually in c:\windows\system32\drivers\etc\hosts, and when you try to edit this file run notepad (or any other preferred editor) as ADMINISTRATOR, otherwise chances are big your modifications wont be saved.
您的主机文件通常在c:\windows\system32\drivers\etc\hosts. 中,当您尝试编辑此文件时,以管理员身份运行记事本(或任何其他首选编辑器),否则很可能无法保存您的修改。
After doing all this, in your browser do a control-f5 (refresh without using the cache).
完成所有这些之后,在您的浏览器中执行 control-f5(刷新而不使用缓存)。
回答by Soufas
After adding the line 127.0.0.1 localhost to the hosts file, copy the contents of hosts file and paste it in another new file, then replace the old hosts files with the new one. This worked for me.
将 127.0.0.1 localhost 行添加到 hosts 文件后,复制 hosts 文件的内容并将其粘贴到另一个新文件中,然后将旧的 hosts 文件替换为新的。这对我有用。
回答by jaison
Resolved Issue by editing /etc/hosts file: I also had similar issue(Able to ping 127.0.0.1, but issue while pinging localhost). I resolved it by removing entries like ::1 localhost, ff81::1%lo0 localhost with only 127.0.0.1 localhost.... I removed rest of the entries for localhost. I done this for my mac.
通过编辑 /etc/hosts 文件解决了问题:我也有类似的问题(能够 ping 127.0.0.1,但在 ping localhost 时出现问题)。我通过删除 ::1 localhost, ff81::1%lo0 localhost with only 127.0.0.1 localhost 之类的条目解决了它。我删除了 localhost 的其余条目。我为我的 mac 做了这个。
After this process I can debug my java application using eclipse.
在这个过程之后,我可以使用 eclipse 调试我的 java 应用程序。
回答by Davide
You can remove comment (# row start) or add 127.0.0.1 localhost In your hosts (folder etc)
您可以删除注释(# row start)或在您的主机(文件夹等)中添加 127.0.0.1 localhost
Open this file with privilege admin
以管理员权限打开此文件
回答by Shariq Raza
This issue also arises if you edited your vhosts.conffile and added a virtual host. To resolve comment out every line of the virtual host entry, e.g. If using xampp, edit your entryin vhosts.conf and comment all the lines (add an # before each line)
如果您编辑了vhosts.conf文件并添加了虚拟主机,也会出现此问题。解决注释掉虚拟主机条目的每一行,例如,如果使用 xampp,请编辑vhosts.conf 中的条目并注释所有行(在每行前添加一个 #)
##<VirtualHost *:80>
##ServerAdmin [email protected]
##DocumentRoot "E:/xampp/htdocs/dummy-host.example.com"
##ServerName dummy-host.example.com
##ServerAlias www.dummy-host.example.com
##ErrorLog "logs/dummy-host.example.com-error.log"
##CustomLog "logs/dummy-host.example.com-access.log" common
##</VirtualHost>
then un-comment or add 127.0.0.1 localhostin your hosts file.
然后取消注释或添加127.0.0.1 localhost您的主机文件。
回答by Robert James Reese
I ran into the same problem with XAMPP on my Mac and (finally) figured out how to fix it. Something similar might work for you on Windows:
我在 Mac 上使用 XAMPP 时遇到了同样的问题,(最终)想出了如何解决它。在 Windows 上,类似的东西可能对你有用:
Even though my /etc/hosts file looked correct, I had a feeling it wasn't working. ("ping localhost" returned no results, but "ping 127.0.0.1" was working.) So, I found that there was a copy of the original hosts file (/etc/hosts~orig) which I replaced my current hosts file with. That did the trick after restarting Apache.
尽管我的 /etc/hosts 文件看起来是正确的,但我还是觉得它不起作用。(“ping localhost”没有返回结果,但“ping 127.0.0.1”正在工作。)所以,我发现有一个原始主机文件(/etc/hosts~orig)的副本,我用它替换了当前的主机文件. 在重新启动 Apache 后,这确实奏效了。
$ sudo mv /etc/hosts /etc/hosts~old
$ sudo cp /etc/hosts~orig /etc/hosts
$ ping localhost

