Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to connect to the Nginx server which is running on my localhost at port 80 using netcat. But I am getting the same error page all the time inspite of whichever header(GET, POST, HEAD) i send. Can somebody explain me why ?

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>

I am running the same above command but still i am getting the html page.

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>

I checked whether my nginx server is running or not using netstat command also. The output is as follows:

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     
share|improve this question

1 Answer 1

up vote 4 down vote accepted

echo (in bash and /bin/echo) don't expand escapes by default. This means that your CR and LF characters are literally being sent as \r and \n. You need to provide the -e option in order to enable escapes.

$ echo -en "GET / HTTP/1.0\r\n\r\n" | nc localhost 80
HTTP/1.1 403 Forbidden
share|improve this answer
    
Thanks a lot ..Now its working :) –  pradeepchhetri Jul 29 '12 at 0:55

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.