我正在 Mac OS X 10.7 上使用 django/postgresql 進行開發,突然我無法透過以下方式存取測試伺服器http://本地主機:8000/。我可以讓它監聽 0.0.0.0:8000 然後它就可以工作了......
然後我注意到 SABnzbd 啟動時出現問題。每當我嘗試啟動它時,它都會死掉並關閉。日誌顯示
IOError: Port 8080 not bound on '127.0.0.1'
運行netstat -an | grep 8080
顯示沒有任何內容在連接埠 8080 上實際偵聽。
然後我嘗試 telnet 並 ping localhost。都不起作用。當我遠端登入時,我得到:
$ telnet localhost
Trying ::1...
telnet: connect to address ::1: Connection refused
Trying 127.0.0.1...
它就掛在那裡。
當我嘗試 ping 時,我得到以下資訊:
$ ping localhost
PING localhost (127.0.0.1): 56 data bytes
Request timeout for icmp_seq 0
Request timeout for icmp_seq 1
Request timeout for icmp_seq 2
奇怪的是,當我遠端登入連接埠 80 時它起作用了!
$ telnet localhost 80
Trying ::1...
Connected to localhost.
Escape character is '^]'.
我的/etc/hosts
文件看起來很正常:
##
# Host Database
#
# localhost is used to configure the loopback interface
# when the system is booting. Do not change this entry.
##
127.0.0.1 localhost
255.255.255.255 broadcasthost
::1 localhost
fe80::1%lo0 localhost
有什麼辦法可以解決這個問題,或者對我來說最簡單的方法就是擦拭它並重新開始?
答案1
現在大多數防火牆都會阻止 ping 請求,我的 OSX Lion 安裝預設情況下也有這種行為。
試著瀏覽到http://本地主機:80如果您可以連接到連接埠 80,並查看該連接埠上正在執行的內容。另請查看您的共享首選項 - 曾經有一個網站共享功能,並且可能使用連接埠 80。
另外,請嘗試遠端登入 localhost:8080,看看是否可以連線(如果可以,則表示另一個應用程式正在使用該連接埠)。
嘗試開啟http://本地主機:8080然後在您的瀏覽器中嘗試找出該連接埠上正在執行的程式。
答案2
在某些情況下,這是由文字編碼問題引起的; /etc/hosts 看起來沒問題,但實際上編碼錯誤。看Mac OS X Mountain Lion 無法 ping/telnet 本機。指向錯誤的公共IP