I'm sorry for the post subject, but I couldn't think of a better name.
I have simple lighttpd setup -> I can browse localhost through web browser without any problems.
Using netcat -> I can connect to foreign servers and get response.
[skyer@sigma-arch ~]$ nc google.com 80 GET / HTTP/1.1 Host: google.com HTTP/1.1 301 Moved Permanently ... and the rest of response from google.com
I'm trying to diagnose why port forwarding doesn't work with my zyxel router, but I can't connect to lighttpd using netcat.
[skyer@sigma-arch ~]$ nc localhost 80 GET / HTTP/1.1 Host: localhost
and nothing comes back, so I exit using Ctrl+C. (Note: there are few new lines which this forum's BB code parser seems to ignore)
Also, web server's access log doesn't list my attempt to connect. As you've probably figured out by now, I'm not very experienced. It could be a problem with my lighttpd configuration or I just can't use netcat properly. Feel free to ask for additional information, and thanks for any answers.
Your requests seem invalid; try "GET / HTTP/1.0", or add a "Connection: close" header. Your server currently expects more requests ( http://redmine.lighttpd.net/projects/1/ … Keep-Alive )
Appending 'connection: close' header doesn't seem to have any effect. I'll dig into it some more...
Try it like this
echo -e "GET http://localhost HTTP/1.0\r\n\r\n" | nc -w 5 localhost 80
Strike0, that one works.
So I guess I just haven't been inputting the right characters. Should have followed the specs. But the same thing seems to work for majority of servers I've tried (maybe Apache is the reason).
There may be some server conf involved as well with the difference, but it should be more that netcat opens the socket with the command you used, but you have to finish the GET request manually. Netcat is interactive in the terminal after you open a socket like that. If you try it again like you did in #1, but _instead_ of hitting ctrl-c you just hit return twice your localhost might reply as well. Or just use "curl http://locahost" to test.
Please mark as solved, if it works. Thanks.
http://www.w3.org/Protocols/rfc2616/rfc … tml#sec2.2
standart new line for http protocol is CRLF.
Not just line feed alone as in unix.
nc send what you are typing in raw mode, so it does not send any CRLF when you hit enter, and lighttpd is not tolerant with newlines.
bsd netcat have the -C option to send CRLF as line-endings.
nc -C localhost 80
Last edited by Tomtix (2015-07-07 13:46:50)
Hi Tomtix, and welcome to Arch Linux.
I thank you for the relevant information, but I hope that the original poster is no longer looking for a solution 2 years later.
Everyone: Anyway, I think this thread is done. I'll go ahead and close it now. If further discussion is warranted, go ahead and start a new thread and link back to this one as appropriate.
Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Like you, I have no idea what you are doing, but I am pretty sure it is wrong...Jasonwryan
How to Ask Questions the Smart Way