A 42 project where we have to create our own HTTP/1.1 web server from scratch, using only C++ 98 Standard Library
git clone https://github.com/alissonmarcs/webserv.git
cd webserv
make
./webserv configs/some_config.conf
# configs/cgi.conf
server
{
host 127.0.0.1; # Ip to attach on.
listen 8000; # Port to listen.
client_max_body_size 10M; # When request has body, limit its size. When no prefixes are used, the integer is interpreted as bytes. You can use M and G prefixes.
error_page 504 error_pages/504.html; # Define custom error pages. When none are defined, the default is used.
location /configs/
{
root ./;
autoindex on; # Enable/disable the listing of an folder when the request asks for an folder.
allowed_methods GET; # Listing of allowed methods
}
}location /car
{
root www;
index other_index.html;
allowed_methods GET;
}The location path, /car, is for select what location will process the request.
location /forms
{
#...
}
location /cgi-bin/
{
#...
}GET /forms/is_prime.html will be processed by location /forms.
GET /cgi-bin/upload.py will be processed by location /cgi-bin.
GET /demo/some_file.html match with no location, so the server will response 404 Not Found.
root tells in what folder the requested file will be searched for.
location /tech
{
root www;
}
location /forms
{
root ./;
}GET /tech/index.html will return ./www/tech/index.html, or 404 Not Found if the file is not found.
GET /forms/up_case.html will return ./forms/up_case.html.
The root value can be set as relative or absolute.
When an folder were requested, you can enable the listing of folder.
location /tech
{
root www;
autoindex on;
allowed_methods GET;
}GET /tech will return the listing of ./www/tech/
When an folder were requested, you can set an default file to be served.
location /tech
{
root www;
index services.html
allowed_methods GET;
}GET /tech will return ./www/tech/services.html.
location /tech
{
root www;
index null.html
autoindex on;
allowed_methods GET;
}When both index and autoindex are enabled, if the file specified in index really exists, it will be returned, if not, the listing of folder will be returned.
GET /tech will return the listing of ./www/tech/.
You can limit the size of body of POST requests.
Use no prefix for bytes, M for megabytes, or G for gigabytes.
