https://github.com/pin3dev/42_webserv
A simple HTTP/1.1 server written in C++, supporting GET, POST, DELETE methods, virtual hosting, CGI script execution, and custom error pages. Ideal for understanding the basic concepts of web servers.
https://github.com/pin3dev/42_webserv
42-webserv 42born2code 42projects 42school cgi-application cgi-script html-css-javascript multiplexing-circuits polling socket-io webserver website
Last synced: 6 days ago
JSON representation
A simple HTTP/1.1 server written in C++, supporting GET, POST, DELETE methods, virtual hosting, CGI script execution, and custom error pages. Ideal for understanding the basic concepts of web servers.
- Host: GitHub
- URL: https://github.com/pin3dev/42_webserv
- Owner: pin3dev
- Created: 2024-04-30T14:17:46.000Z (about 2 years ago)
- Default Branch: main
- Last Pushed: 2024-08-14T11:53:17.000Z (almost 2 years ago)
- Last Synced: 2025-07-13T22:26:47.824Z (10 months ago)
- Topics: 42-webserv, 42born2code, 42projects, 42school, cgi-application, cgi-script, html-css-javascript, multiplexing-circuits, polling, socket-io, webserver, website
- Language: C++
- Homepage:
- Size: 50.5 MB
- Stars: 3
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Webserv
Introduction •
Structure •
Docs •
Cloning •
Usage •
Norms •
Theoretical
Contributors
**Webserv** is a lightweight HTTP/1.1 web server built from scratch in C++. It is capable of serving static files, executing CGI scripts, handling custom routes, virtual hosts, and more.
This project aims to deepen understanding of how web servers work under the hood, while applying knowledge of sockets, HTTP protocol, file I/O, and configuration parsing.
The project is organized as follows:
* `exe/`: Core source files of the server
* `inc/`: Header files
* `configs/`: Example configuration files
* `www/`: Static web content and HTML tutorials
A `Makefile` is provided to facilitate compilation.
For a detailed breakdown of how the project works, please visit the documentation link below:
To clone this repository and compile the project, run the following commands:
```bash
git clone https://github.com/pin3dev/42_Webserv.git
cd 42_Webserv
```
This will download the project to your local machine. Once inside the `webserv` directory, run the provided `Makefile` to compile the project.
### Makefile
The `Makefile` includes the following rules:
* `make`: Builds the `webserv` executable
* `make clean`: Removes object files
* `make fclean`: Removes object files and binary
* `make re`: Rebuilds everything from scratch
To compile the project, run:
```bash
make
```
This will generate the executable `webserv`, which can then be launched with a configuration file.
### Basic Usage
1. Start the server:
```bash
./webserv [config_file]
```
> If no config file is specified, it defaults to `configs/default.conf`.
### Configuration
The configuration file allows you to set up the server and define its behavior. Below is an example of a basic configuration:
```bash
server {
server_name www.site1;
listen 8080;
host localhost;
root www/site1;
index index.html;
client_max_body_size 2M;
error_page 404.html;
location / {
allow_methods GET;
#try_file tutorial.html;
}
location /upload {
allow_methods GET DELETE;
}
location .py {
allow_methods GET POST;
cgi_path /cgi;
cgi_ext .py;
upload_to /upload;
}
location /favicon.ico {
allow_methods GET;
}
location /assets {
allow_methods GET;
autoindex on;
}
location /redirect {
allow_methods GET;
return /;
}
}
```
* `listen`: Port the server listens on
* `server_name`: Virtual host domain
* `root`: Document root for serving files
* `index`: Default file to serve
* `error_page`: Custom error page
* `location`: Define specific behavior for URI paths
* `autoindex`: Enable directory listing
* `cgi_path` / `cgi_ext`: CGI execution path and file extension
* `allow_methods`: Accepted HTTP methods (GET, POST, DELETE)
* `upload_to`: File upload destination directory
### 🧪 Testing the Server
A tutorial page is available at:
```bash
http://localhost:/tutorial.html
```
This page provides step-by-step instructions for testing routes using `curl`, HTTP clients, or your browser. It includes examples for different methods like GET, POST, and DELETE.
## ⚠️ Norms and Guidelines Disclaimer
This project strictly follows the [42 Norm](https://github.com/pin3dev/42_Cursus/blob/b9cd0fe844ddb441d0b3efb98abcee92aee49535/assets/General/norme.en.pdf). Some design decisions may seem unusual but are required to comply with school coding standards.
All supporting material and theory used for this project are documented and available here:
Feel free to open issues or contribute improvements via pull requests!