Webserv is a simple HTTP server written in C++98 as part of a school project. It supports handling multiple client connections, serving static files, handling basic HTTP methods (GET, POST, DELETE), and running CGI scripts (like Python and PHP).
The project is designed to mimic the basic behavior of web servers such as NGINX, with a focus on understanding HTTP protocol and server-side networking.
- Support for multiple servers running on different ports.
- Handles HTTP methods: GET, POST, and DELETE.
- CGI execution (supports extensions like
.phpand.py). - File uploading support.
- Autoindex (directory listing) feature.
- Custom error pages handling.
- Limits client body size.
- Fully non-blocking I/O using
poll().
Example of server configuration:
server {
listen 127.0.0.1;
listen 127.0.0.1:8081;
listen 127.0.0.1:8082;
listen 127.0.0.1:8083;
server_name localhost;
location / {
methods GET POST DELETE;
root /Users/abayar/;
autoindex ON;
upload ./upload/;
error_page 406 502 503 504 /Desktop/;
}
location /upload {
methods GET POST DELETE;
root /Users/abayar/Desktop/;
cgi_path php;
}
client_max_body_size 44m;
}
server {
listen 127.0.0.1;
server_name localhost2;
location / {
methods GET POST;
root /Users/abayar/Desktop/;
index index.html;
upload ./upload/;
cgi_path py;
}
client_max_body_size 43m;
}
make./webserv [config_file]Example:
./webserv conf/webserv.confmake— Compile the project.make clean— Remove the compiled executable.make fclean— Clean all generated files.make re— Recompile the project.
- parsing/ — Handles configuration file parsing and request parsing.
- cgi/ — CGI handling (executing scripts).
- methods/ — HTTP methods handling (GET, POST, DELETE).
- server.cpp — Main server logic.
- http_TcpServer.cpp — TCP server implementation.
- C++98
- No external libraries
- Compatible with browsers (tested with Chrome, Firefox, etc.)
- This project is for educational purposes, focusing on understanding HTTP, socket programming, and server behavior.
- The server is compatible with basic static websites and simple CGI-based web applications.