Troubleshooting httpd with netcat
netcat is the swiss-army knife of networking. It can be a valuable tool to help diagnose networking errors in your web server.
$ print "GET / HTTP/1.1\nHostname: www.example.com\r\n\r\n" | nc www.example.com 80
You may get a few possible responses:
302 Response
A 302 response indicates that the web page has been moved.
This will occur if openhttpd is set to redirect to port 443:
HTTP/1.0 302 Found
Date: Tue, 23 Feb 2021 14:01:28 GMT
OpenBSD httpd
Connection: close
Content-Type: text/html
Content-Length: 486
Location: https://www.example.com/index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>302 Found</title>
<style type="text/css"><!--
body { background-color: white; color: black; font-family: 'Comic Sans MS', 'Chalkboard SE', 'Comic Neue', sans-serif; }
hr { border: 0; border-bottom: 1px dashed; }
@media (prefers-color-scheme: dark) {
body { background-color: #1E1F21; color: #EEEFF1; }
a { color: #BAD7FF; }
}
--></style>
</head>
<body>
<h1>302 Found</h1>
<hr>
<address>OpenBSD httpd</address>
</body>
</html>
Connection closed by foreign host.
This response indicates that
HTTP/1.0 302 Found
Date: Tue, 23 Feb 2021 14:01:28 GMT
OpenBSD httpd
Connection: close
Content-Type: text/html
Content-Length: 486
Location: https://www.example.com/index.html