Webserv is a lightweight web server designed to handle common HTTP methods efficiently. It allows users to browse files directly from a web browser while supporting essential web server functionalities.
- ✅ Non-blocking sockets (handles multiple clients simultaneously)
- ✅ Supports HTTP methods:
GET
,POST
,DELETE
- ✅ Autoindex (directory listing)
- ✅ File upload
- ✅ CGI support (Common Gateway Interface)
- ✅ Redirections
- ✅ Sessions & Cookies
- ✅ Basic authentication
- ✅ Chunked transfer encoding
- ✅ Custom error pages
- ✅ Configurable server settings
- ✅ Streaming responses (chunked response handling)
- ✅ Multiple server blocks
- ✅ Client body size limitation
- ✅ Timeout control for CGI scripts
- ✅ Logging and error reporting
- ✅ Support for static and dynamic content
- C++98
- CMake
- Make
- A C++ compiler
git clone https://github.com/bablilayoub/webserv
cd webserv
make
Start the server with a custom configuration file:
./webserv /path/to/config_file.conf
If no configuration file is provided, the server will use default settings.
To test the server locally, open a browser and navigate to:
http://127.0.0.1:8080
To upload a file via curl
:
curl -X POST -F "file=@/path/to/your/file" http://127.0.0.1/upload
Webserv uses a simple text-based configuration file structured as follows:
server {
host 127.0.0.1;
listen 8080;
limit_client_body_size 1000000;
root_folder /path/to/your/root/folder;
error_page 404 /custom_404.html;
location / {
index index.html;
autoindex on;
upload_dir /path/to/your/upload/folder;
accepted_methods GET POST;
cgi_extensions php py;
php_cgi_path /path/to/your/php-interpreter;
python_cgi_path /path/to/your/python-interpreter;
cgi_timeout 5;
}
location /login {
index login.php;
upload_dir /path/to/your/upload/folder;
accepted_methods GET POST;
cgi_extensions php;
php_cgi_path /path/to/your/php-interpreter;
cgi_timeout 10;
}
location /redirect {
redirect 301 /redirected;
}
location /static {
root_folder /var/www/static;
accepted_methods GET;
}
}
-
Hosting a Static Website:
- Place HTML, CSS, and JS files in
/var/www/static
and configure a/static
route. - Access the site via
http://127.0.0.1:8080/static/index.html
- Place HTML, CSS, and JS files in
-
Enabling File Uploads:
- Ensure
upload_dir
is properly set. - Use
curl
or a web form to send files to the server.
- Ensure
-
Running a PHP-based Login System:
- Configure a
/login
location withphp_cgi_path
. - Ensure the PHP interpreter is correctly installed.
- Configure a
This project is open-source and available under the MIT License.