Introduction
The following guide provides the steps required to create a very primitive HTTP server.
The utility of this would mainly be for basic network connectivity tests of various kinds where you need a way to confirm if data is capable of being sent to and from a specific port via HTTP on the application layer, and TCP on the Transport Layer.
Procedure
- Login to the server where the network connectivity issue is present via SSH or Console as the root user
- Ensure that the netcat and screen packages are installed
yum install screen netcat -y
- Create a document root for your HTTP server
mkdir -pv /root/nc-webserver-docroot/
- Create the file that will hold your mini application script that produces a response:
touch /root/nc-webserver-docroot/httpresponse.sh
- Open the file with the text editor of your choice and add the following contents:
#!/bin/bash
printf 'HTTP/1.1 200 OK\n\n%s' "$(cat /root/nc-webserver-docroot/index.html)" - Make the script executable:
chmod +x /root/nc-webserver-docroot/httpresponse.sh
- Create the index.html file that will store the html for the response:
touch /root/nc-webserver-docroot/index.html
- Open the index.html file with the text editor of your choice and add the following contents:
<!doctype html>
<html lang="en">
<head>
<title>NETCAT TEST</title>
</head>
<body>
<h1>NETCAT TEST</h1>
<p>Connection Successful</p>
</body>
</html> - Start a screen session:
screen -S ncatWebserverTest
- Start the netcat HTTP server with the following command. Be sure to replace PORT with a suitable port that has not already been claimed by another service on the server.
ncat -lv PORT -c /root/nc-webserver-docroot/httpresponse.sh --keep-open
- Use the following key combination to create a new screen window so that you can use curl to make a request to the webserver that you just started:
CTRL + a + c
- Make a curl request to the HTTP server that you just started. Be sure to replace xxx.xxx.xxx.xxx with either your server's IP address, or domain. Also be sure to replace PORT with the port that you used for the HTTP server above.
curl -vvv http://xxx.xxx.xxx.xxx:PORT
- You may also want to visit the URL from your browser, or from multiple different computers and locations depending on the type of issue that you are troubleshooting.
- Once you have made a request, switch back to the HTTP server screen. The HTTP server that you started with netcat provides detailed information about each request that it recieved. You can switch back to the HTTP server screen by using the following shortcut. Please review the screen manual page if you have difficulty switching between screens.
CTRL + a + n
Comments
0 comments
Article is closed for comments.