从命令行使用 wget 调试网页错误

系统 Linux
调试 Web 服务器的一种方法是使用 wget 命令行程序,使用 -S 选项来显示所有的服务器响应。当使用 wget 进行调试时,我也喜欢使用 -O 选项将输出保存到一些临时文件中,以备以后需要查看其内容。

[[424697]]

调试 Web 服务器的一种方法是使用 wget 命令行程序。

有时在管理一个网站时,事情会被搞得一团糟。你可能会删除一些陈旧的内容,用重定向到其他页面来代替。后来,在做了其他改动后,你发现一些网页变得完全无法访问了。你可能会在浏览器中看到一个错误:“该页面没有正确重定向”,并建议你检查你的 cookie。 

Redirect loop example in Firefox

调试这种情况的一个方法是使用 wget 命令行程序,使用 -S 选项来显示所有的服务器响应。当使用 wget 进行调试时,我也喜欢使用 -O 选项将输出保存到一些临时文件中,以备以后需要查看其内容。

  1. $ wget -O /tmp/test.html -S http://10.0.0.11/announce/
  2. --2021-08-24 17:09:49-- http://10.0.0.11/announce/
  3. Connecting to 10.0.0.11:80... connected.
  4.  
  5. HTTP request sent, awaiting response...
  6.  
  7. HTTP/1.1 302 Found
  8. Date: Tue, 24 Aug 2021 22:09:49 GMT
  9. Server: Apache/2.4.48 (Fedora)
  10. X-Powered-By: PHP/7.4.21
  11. Location: http://10.0.0.11/assets/
  12. Content-Length: 0
  13. Keep-Alive: timeout=5, max=100
  14. Connection: Keep-Alive
  15. Content-Type: text/html; charset=UTF-8
  16. Location: http://10.0.0.11/assets/ [following]
  17. --2021-08-24 17:09:49-- http://10.0.0.11/assets/
  18. Reusing existing connection to 10.0.0.11:80.
  19.  
  20. HTTP request sent, awaiting response...
  21. HTTP/1.1 302 Found
  22. Date: Tue, 24 Aug 2021 22:09:49 GMT
  23. Server: Apache/2.4.48 (Fedora)
  24. X-Powered-By: PHP/7.4.21
  25. Location: http://10.0.0.11/announce/
  26. Content-Length: 0
  27. Keep-Alive: timeout=5, max=99
  28. Connection: Keep-Alive
  29. Content-Type: text/html; charset=UTF-8
  30. Location: http://10.0.0.11/announce/ [following]
  31. --2021-08-24 17:09:49-- http://10.0.0.11/announce/
  32. Reusing existing connection to 10.0.0.11:80.
  33. .
  34. .
  35. .
  36. 20 redirections exceeded.

我在这个输出中省略了很多重复的内容。通过阅读服务器的响应,你可以看到 http://10.0.0.11/announce/ 立即重定向到 http://10.0.0.11/assets/,然后又重定向到 http://10.0.0.11/announce/。以此类推。这是一个无休止的循环,wget 将在 20 次重定向后退出。但有了这些调试信息,你可以修复重定向,避免循环。 

 

责任编辑:庞桂玉 来源: Linux中国
相关推荐

2014-04-10 10:10:16

KVMDebianUbuntu

2012-02-08 16:37:36

ibmdw

2020-12-06 08:00:46

scanimage命令行Linux

2018-03-14 14:27:00

2010-05-27 14:48:45

SVN命令行使用说明

2009-09-22 14:17:05

2022-06-16 14:54:53

hilog工具鸿蒙

2018-06-19 16:05:27

LinuxStratis存储

2023-08-01 13:31:18

模型Alpacaicuna

2020-10-31 08:20:39

curl命令命令行互联网

2016-12-15 08:30:02

Linux命令

2017-03-13 08:50:35

科技新闻早报

2010-05-11 11:34:44

2010-02-04 15:17:48

Linux wget

2019-02-13 09:20:13

Linux命令行more

2022-06-30 12:19:22

Linux

2019-08-27 08:00:10

OpenStack命令虚拟机

2019-07-15 05:50:19

Linux命令行VirtualBox版

2019-01-22 13:46:01

LinuxUnix系统命令行

2014-10-22 12:03:14

Linux嗅探HTTP
点赞
收藏

51CTO技术栈公众号