This project is an exploration of the HTTP protocol by building a custom HTTP server in C++98. It provides a hands-on experience in understanding the intricacies of web communication, allowing users to test the server with a browser. The project covers both mandatory and bonus features, emphasizing non-blocking operations, configuration files, and CGI support.
- Unix-compliant system
- c++ compiler
- make
- php cgi ( optional )
- clone the repository
git clone https://github.com/0xhoussam/http-1.1.git && cd http-1.1
- create the following directories
mkdir -p /tmp/webserv/cgi
- compile the project
make
- create a config file
default test.com:1337 {
route / {
methods GET;
root ./static/;
index index.html;
}
}
the syntax is inspired by Caddy server config file
- run the server
./http config_file
- we need an example of a static website you can use anyone you prefer for demonstration i will be using this repo as an example
git clone https://github.com/YaninaTrekhleb/restaurant-website.git website
- let's add a config to server this website
default website.com:1337 {
route / {
methods GET POST;
root ./website/;
index index.html;
}
}
save this in a file i will be saving it in a file called website.conf
make sure that the root directive points exactly where the folder of the repo you cloned
- now serve the website
./http website.conf
in this example, I will use WordPress as an example
- download WordPress from their website
- configure a server
default example.com:1337 {
route / {
methods GET POST;
root ./wordpress/;
index index.php;
cgi php /usr/bin/php-cgi;
}
}
- make sure that the root points exactly to where you put WordPress
- make sure that php cgi is installed and write its path in the CGI
- directive an easy way to find its path is by running
which php-cgi
- if you open the browser and go to
localhost:1337
WordPress should be served