https://localhost 顯示 IIS 默認頁面或報錯。https://127.0.0.1 正常顯示 WAMP/Apache 頁面。mod_fcgid 佔用提示。localhost 域名解析異常,未正確指向 127.0.0.1。Windows 默認 hosts 文件可能被修改、清空或權限受限,導致解析失敗或解析到錯誤 IP(如 ::1 IPv6)。
ping localhost
# 應返回 127.0.0.1
# 若返回 ::1 或其他 IP,說明 hosts 有問題
C:\Windows\System32\drivers\etc\hosts。127.0.0.1 localhost
::1 localhost
若 `netstat -ano | findstr :80` 顯示 PID 屬於 `httpd.exe` (Apache) 正常;若屬於 `System` (PID 4) 或 `w3wp.exe` (IIS),需停用 IIS 或修改 Apache 端口。
httpd.conf,將 `Listen 80` 改為 `Listen 8080`,訪問 https://localhost:8080。若 Apache 啟動報錯 mod_fcgid: can't create shared memory,編輯 httpd.conf 或 extra/httpd-fcgid.conf,添加/調整:
FcgidInitialEnv PHPRC "C:/wamp64/bin/php/php7.4.33"
FcgidMaxRequestLen 1073741824
# 確保 FcgidIPCDir 指向可寫目錄
FcgidIPCDir "C:/wamp64/tmp/fcgid"
net stop wampapache64
net start wampapache64
# 或 WAMP 托盤圖標 → Restart All Services
| 現象 | 可能原因 | 對策 |
|---|---|---|
| hosts 保存提示「拒絕訪問」 | 權限不足/殺毒軟件攔截 | 管理員運行記事本/暫時關閉實時防護 |
| ping localhost 正常但瀏覽器仍錯 | 瀏覽器代理/緩存/Hosts 解析緩存 | 清除瀏覽器緩存/關閉代理/無痕模式測試 |
| Apache 啟動即退出 | 配置語法錯誤/端口被佔/模塊缺失 | 運行 httpd -t 檢查語法,查看 error.log |
localhost 無法訪問 90% 是 **hosts 文件缺失或錯誤**。以管理員身份修復 hosts、刷新 DNS、確保端口 80 無衝突、重啟 Apache,即可恢復正常。建議將 hosts 文件設置為「只讀」防止被第三方軟件篡改。