从命令行调试网页错误

调试 Web 服务器的一种方法是使用 wget 命令行程序。
33 位读者喜欢这篇文章。
Digital creative of a browser on the internet

有时在管理网站时,事情可能会变得混乱。您可能会删除一些过时的内容,并将其替换为重定向到其他页面。 稍后,在进行其他更改后,您会发现某些网页完全无法访问。 您可能会在浏览器中看到错误,提示“页面未正确重定向”,并建议您检查 Cookie。

调试这种情况的一种方法是使用 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 次重定向后退出。 但是,有了这些调试信息,您可以修复重定向并避免循环。

接下来阅读什么
photo of Jim Hall
Jim Hall 是一位开源软件倡导者和开发者,以 GNOME 中的可用性测试以及作为 FreeDOS 的创始人兼项目协调员而闻名。

1 条评论

哇哦 Jim,真是个好主意! 我可以想到大约 200 次我希望自己想到像您建议的那样使用 wget 的情况。

谢谢你,谢谢你,谢谢你!

Creative Commons License本作品采用知识共享署名-相同方式共享 4.0 国际许可协议进行许可。
© . All rights reserved.