Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a very simple netcat webserver set up to display the /etc/motd file for some machines, which works fine in Firefox, but intermittently fails in Chrome. I suspect it's an HTTP header / caching issue, but I'm not sure what I need to do to make Chrome behave.

My script:


while true
do { 
  echo -e "HTTP/1.1 200 OK\r\nContent-Length: $(cat -s /etc/motd | wc -c)\r\nContent-Type: text/plain\r\n\r\n"
  cat -s /etc/motd;
} | nc -l 2020

Which serves up:

HTTP/1.1 200 OK
Content-Length: 252
Content-Type: text/plain

.../etc/motd file contents....

Firefox seems to handle this fine, as does Chrome sometimes, but other times it returns:

This webpage is not available

Google Chrome's connection attempt to was rejected. The website may be down, or your network may not be properly configured.

I haven't seen any particular pattern causing the connection to fail, but my current theory is there's some sort of additional header Chrome expects to see, or perhaps the connection is being closed abruptly which Chrome assumes means the machine is down and doesn't actually re-try it.

share|improve this question

netcat was not designed for scalability, merely a debugging tool. If the connection is closed, then nc stops listening. Since you have an infinite loop that starts nc again, you often can open the page. Keep in mind that most browsers initially request a resource (for example, /) but also /favicon.ico. That is a case that this construct may not handle well due to the short period where nc does not run.

If you need a simple webserver, you can use Python. For example, to serve the current directory:

python -m SimpleHTTPServer 2020

If you are using Python 3, you need to run:

python -m http.server 2020

Documentation for BaseHTTPServer, you only need to add a request handler.

share|improve this answer
Yes sorry, they were supposed to be double quotes. The header output in my question is exactly what my browser is seeing. – dimo414 Sep 5 '12 at 17:36

Your Answer


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.