Table of Contents
Webserv is a project from the 42 curriculum, aiming to build a webserver based on NGINX. The implementation follows the latest guidelines from the RFCs for the HTML protocol and CGI protocol. The server is completely build in C++ and uses poll as the multiplexer to manage the socket connections. The implementation covers the following features:
- Handling of
GET
,POST
andDELETE
requests - Serving of every common Filetype
- Nginx-like configuration with config files
- Common Gateway Interface for every requests type
- Autoindexing
The following contains a description of how to use the program. It is recommend to run in an unix (linux or mac) environment. As installing make and compilers in windows can be quite tedious. You can find a tutorial and setting up an ubuntu virtual machine here
You need to have make and gcc installed. For mac you need also xcode to perform the installation.
- linux (Debian based)
sudo apt install build-essential
- MAC-OS
xcode-select --install
- Clone the repo
git clone https://github.com/oph-design/webserv.git
- Build the executabel at the root of the repository
make webserv
- Run the executable with your desired config file
./webserv conf/webserv.conf
- Open localhost on your browser with the specified port number
curl localhost:1234
This section provides a guide for configuring your web server using a syntax similar to Nginx. The configuration file allows you to define server blocks, location blocks, and limit_except blocks to tailor your web server's behavior.
A server block defines the settings for a specific virtual server. Below is the syntax for a server block:
server {
listen PORT;
client_max_body_size SIZE;
server_name DOMAIN;
index INDEX_FILE;
root ROOT_DIRECTORY;
error_page CODE PATH;
timeout TIMEOUT
# Add location blocks and limit_except blocks here
}
PORT
: The port number the server will listen on.SIZE
: Maximum body size for client requests.DOMAIN
: The domain name associated with the server.INDEX_FILE
: Default file to serve if no specific file is requested.ROOT_DIRECTORY
: The root directory for serving files.CODE
: HTTP status code for which to display the custom error page.PATH
: Path to the custom error page.TIMEOUT
: The time until a client should time out in seconds.
A location block defines settings for specific URL paths within a server block. Below is the syntax for a location block:
location PATH {
autoindex on|off;
client_max_body_size SIZE;
index INDEX_FILE;
root ROOT_DIRECTORY;
cgi_pass CGI_DIRECTORY;
error_page CODE PATH;
cgi_processing CGI;
# Add limit_except block here if wanted
}
PATH
: URL path to apply the location settings to.autoindex
: Enable or disable directory listing.SIZE
: Maximum body size for client requests.INDEX_FILE
: Default file to serve for this location.ROOT_DIRECTORY
: The directory to serve files from.CGI_DIRECTORY
: Path where the CGI-Scripts are located.CODE
: HTTP status code for which to display the custom error page.PATH
: Path to the custom error page.CGI
: Allowed CGIs.
A limit_except block restricts the HTTP methods allowed on a specific URL path. Below is the syntax for a limit_except block:
limit_except METHODS {
deny all;
}
METHODS
: List of HTTP methods to restrict. (e.g., GET, POST, PUT, DELETE, etc.)
Remember to replace placeholders (PORT, SIZE, DOMAIN, etc.) with actual values relevant to your web server setup.
Note: This configuration is an abstraction and not an actual web server configuration. Refer to your web server's documentation for implementation details and further customization.
Michael Graefen
Florian Sandel
Ole-Paul Heinzelmann