我正尝试使用netcat连接到端口80上运行在本地主机上的Nginx服务器。 但是,尽pipe我发送了任何头文件(GET,POST,HEAD),但我总是收到相同的错误页面。 有人能解释我为什么吗?
pradeep@pradeep-laptop:~$ echo -n "GET / HTTP/1.0\r\n\r\n" | nc localhost 80 <html> <head><title>400 Bad Request</title></head> <body bgcolor="white"> <center><h1>400 Bad Request</h1></center> <hr><center>nginx/1.1.19</center> </body> </html>
我正在运行上面的命令,但仍然我正在获取HTML页面。
pradeep@pradeep-laptop:~$ echo -n "HEAD / HTTP/1.0\r\n\r\n" | nc localhost 80 <html> <head><title>400 Bad Request</title></head> <body bgcolor="white"> <center><h1>400 Bad Request</h1></center> <hr><center>nginx/1.1.19</center> </body> </html>
我也检查了我的nginx服务器是否正在运行或不使用netstat命令。 输出如下:
root@pradeep-laptop:/# netstat -taupen| grep LISTEN | grep :80 tcp 0 0 0.0.0.0:80 0.0.0.0:* LISTEN 0 264102 13723/nginx
echo (在bash和/bin/echo )默认不会扩展转义。 这意味着您的CR和LF字符字面上是作为\r和\n 。 您需要提供-e选项才能启用转义。
$ echo -en "GET / HTTP/1.0\r\n\r\n" | nc localhost 80 HTTP/1.1 403 Forbidden