從命令行使用 wget 調試網頁錯誤

調試 Web 服務器的一種方法是使用 wget 命令行程序,使用 -S 選項來顯示所有的服務器響應。當使用 wget 進行調試時,我也喜歡使用 -O 選項將輸出保存到一些臨時文件中,以備以後需要查看其內容。

從命令行使用 wget 調試網頁錯誤從命令行使用 wget 調試網頁錯誤

調試 Web 服務器的一種方法是使用 wget 命令行程序。

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

從命令行使用 wget 調試網頁錯誤從命令行使用 wget 調試網頁錯誤

Redirect loop example in Firefox

調試這種情況的一個方法是使用  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 Found
Date: Tue, 24 Aug 2021 22:09:49 GMT
Server: Apache/2.4.48 (Fedora)
X-Powered-By: PHP/7.4.21
Location: http://10.0.0.11/assets/
Content-Length: 0
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Location: 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 Found
Date: Tue, 24 Aug 2021 22:09:49 GMT
Server: Apache/2.4.48 (Fedora)
X-Powered-By: PHP/7.4.21
Location: http://10.0.0.11/announce/
Content-Length: 0
Keep-Alive: timeout=5, max=99
Connection: Keep-Alive
Content-Type: text/html; charset=UTF-8
Location: 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 次重定向後退出。但有了這些調試信息,你可以修復重定向,避免循環。

本文地址:https://www.linuxprobe.com/wget-page-web1.html

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章