首頁 > 易卦

從命令列使用 wget 除錯網頁錯誤

作者:由 硬核老王 發表于 易卦日期:2021-12-10

行什麼差錯

除錯 Web 伺服器的一種方法是使用 wget 命令列程式。

從命令列使用 wget 除錯網頁錯誤

有時在管理一個網站時,事情會被搞得一團糟。你可能會刪除一些陳舊的內容,用重定向到其他頁面來代替。後來,在做了其他改動後,你發現一些網頁變得完全無法訪問了。你可能會在瀏覽器中看到一個錯誤:“該頁面沒有正確重定向”,並建議你檢查你的 cookie。

從命令列使用 wget 除錯網頁錯誤

除錯這種情況的一個方法是使用

wget

命令列程式,使用

-S

選項來顯示所有的伺服器響應。當使用

wget

進行除錯時,我也喜歡使用

-O

選項將輸出儲存到一些臨時檔案中,以備以後需要檢視其內容。

$ wget -O /tmp/test。html -S http://10。0。0。11/announce/——2021-08-24 17:09:49—— http://10。0。0。11/announce/Connecting to 10。0。0。11:80。。。 connected。HTTP request sent, awaiting response。。。 HTTP/1。1 302 FoundDate: Tue, 24 Aug 2021 22:09:49 GMTServer: Apache/2。4。48 (Fedora)X-Powered-By: PHP/7。4。21Location: http://10。0。0。11/assets/Content-Length: 0Keep-Alive: timeout=5, max=100Connection: Keep-AliveContent-Type: text/html; charset=UTF-8Location: http://10。0。0。11/assets/ [following]——2021-08-24 17:09:49—— http://10。0。0。11/assets/Reusing existing connection to 10。0。0。11:80。HTTP request sent, awaiting response。。。 HTTP/1。1 302 FoundDate: Tue, 24 Aug 2021 22:09:49 GMTServer: Apache/2。4。48 (Fedora)X-Powered-By: PHP/7。4。21Location: http://10。0。0。11/announce/Content-Length: 0Keep-Alive: timeout=5, max=99Connection: Keep-AliveContent-Type: text/html; charset=UTF-8Location: http://10。0。0。11/announce/ [following]——2021-08-24 17:09:49—— http://10。0。0。11/announce/Reusing existing connection to 10。0。0。11:80。。。。20 redirections exceeded。

我在這個輸出中省略了很多重複的內容。透過閱讀伺服器的響應,你可以看到

http://10。0。0。11/announce/

立即重定向到

http://10。0。0。11/assets/

,然後又重定向到

http://10。0。0。11/announce/

。以此類推。這是一個無休止的迴圈,

wget

將在 20 次重定向後退出。但有了這些除錯資訊,你可以修復重定向,避免迴圈。

via: https://opensource。com/article/21/9/wget-debug-web-server

作者:Jim Hall選題:lujun9972譯者:geekpi校對:wxy

本文由 LCTT原創編譯,Linux中國榮譽推出