A simple web server for learning purpose, a revised edition of the tinyhttpd created November 1999 by J. David Blackstone.
- To compile, you need a Linux distribution with gcc or clang that supports C99
- Clone the git repository:
git clone https://github.com/shunlir/tinyhttpd.git
- Change to the repo:
cd tinyhttpd
- Compile:
make
- You need perl and its CGI module installed:
- For Ubuntu/Debian:
sudo apt-get install perl libcgi-pm-perl
- For Fedora/RHEL/Centos:
sudo yum install perl perl-CGI
- For Ubuntu/Debian:
- Start tinyhttpd:
./tinyhttpd 8088
- Start a web browser:
- Enter
http://localhost:8088
(client uses HTTP GET /) - Type a color name in the textbox, such as 'pink', click at the 'submit query' button (client uses HTTP POST /color.cgi)
- Enter 'http://localhost:8088/color.cgi?color=pink' (client uses HTTP GET /color.cgi)
- Enter
- It's quite a simple http server, only HTTP 1.0 GET and POST method
- But it demonstrates how to serve static html files and dynmic html content generated by CGI scripts
- Demonstrate the use of network I/O (TCP socket), file I/O, and pthread
- Go and enjoy it! You can improve it as you like!