You are not logged in.

#1 2013-06-27 17:06:27

skyer
Member
Registered: 2012-06-25
Posts: 56

can't get lighttpd to reply with netcat

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.

Offline

#2 2013-06-27 17:44:25

Spider.007
Member
Registered: 2004-06-20
Posts: 1,175

Re: can't get lighttpd to reply with netcat

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 )

Offline

#3 2013-06-28 14:06:05

skyer
Member
Registered: 2012-06-25
Posts: 56

Re: can't get lighttpd to reply with netcat

Appending 'connection: close' header doesn't seem to have any effect. I'll dig into it some more...

Offline

#4 2013-06-29 08:29:34

Strike0
Member
From: Germany
Registered: 2011-09-05
Posts: 1,429

Re: can't get lighttpd to reply with netcat

Try it like this

echo -e "GET http://localhost HTTP/1.0\r\n\r\n" | nc -w 5 localhost 80 

Offline

#5 2013-07-02 17:55:24

skyer
Member
Registered: 2012-06-25
Posts: 56

Re: can't get lighttpd to reply with netcat

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).

Offline

#6 2013-07-02 20:58:51

Strike0
Member
From: Germany
Registered: 2011-09-05
Posts: 1,429

Re: can't get lighttpd to reply with netcat

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.

Offline

#7 2015-07-07 13:43:31

Tomtix
Member
Registered: 2015-03-03
Posts: 5

Re: can't get lighttpd to reply with netcat

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)

Offline

#8 2015-07-07 14:34:32

ewaller
Administrator
From: Pasadena, CA
Registered: 2009-07-13
Posts: 19,739

Re: can't get lighttpd to reply with netcat

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.

Thanks
https://wiki.archlinux.org/index.php/Fo … bumping.22


Nothing is too wonderful to be true, if it be consistent with the laws of nature -- Michael Faraday
Sometimes it is the people no one can imagine anything of who do the things no one can imagine. -- Alan Turing
---
How to Ask Questions the Smart Way

Offline

Board footer

Powered by FluxBB