Score: 125/100
Finished: 20.01.2025
This project is about writing your our HTTP server.
- HTTP/1.1 compliant and non-blocking
- supports
GET
,POST
andDELETE
methods - native File uploads using
multipart/form-data
CGI
scriptsautoindex
feature- HTTP redirections
- custom error pages
- chunked transfer encoding
keep-alive
connections- fully configurable using a
nginx
-like configuration file. see Configuration
The repository also includes some showcases/tests in the examples
directory.
git clone ...
cd webserv
make
./webserv [config_file]
http {
server {
listen 80;
server_name localhost 127.0.0.1;
root /www;
index /index.html;
client_max_body_size 1024m;
client_body_buffer_size 1024k;
client_header_buffer_size 1024k;
request_timeout 10m;
location / {
allow_methods GET;
autoindex on;
}
}
}
Note
If there are multiple servers with the same host:port
pair, the first one will be used.
http {
server {
...
}
server {
...
}
}
directive | description | example |
---|---|---|
listen |
ip and/or port to listen on | 0.0.0.0:80 |
server_name |
server name | localhost |
root |
root directory | /www |
index |
default index file | /index.html |
client_max_body_size |
maximum body size | 1024m |
client_body_buffer_size |
body buffer size | 1024k |
client_header_buffer_size |
header buffer size | 1024k |
request_timeout |
request timeout | 10m |
error_page |
custom error page (<code> <filepath> ) |
404 /404.html |
location |
location block | location / {...} |
Specified within a location
block. The server will use the closest matching location block.
directive | description | example |
---|---|---|
allow_methods |
allowed methods | GET POST DELETE |
autoindex |
enable autoindex | on |
cgi |
cgi script (<ext> <path> ) |
.php /usr/bin/php |
upload_dir |
upload directory (by setting this uploads are enabled) | /uploads |
root |
root directory | /www |
index |
default index file | /index.html |
return |
only for redirect (<status> <location> ) |
301 /new |
location /youtube {
return 301 https://www.youtube.com;
}
This project was written as part of the 42 cursus at 42 Heilbronn by: