Skip to content

Implementation of a minimalistic webserver for ecole 42

Notifications You must be signed in to change notification settings

oph-design/webserv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Webserv

GitHub code size in bytes Code language count GitHub top language GitHub last commit

Table of Contents
  1. About The Project
  2. Getting Started
  3. Configuration
  4. Contact

About The Project

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 and DELETE requests
  • Serving of every common Filetype
  • Nginx-like configuration with config files
  • Common Gateway Interface for every requests type
  • Autoindexing

Getting Started

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

Prerequisites

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

Usage

  1. Clone the repo
    git clone https://github.com/oph-design/webserv.git
  2. Build the executabel at the root of the repository
    make webserv
  3. Run the executable with your desired config file
    ./webserv conf/webserv.conf
  4. Open localhost on your browser with the specified port number
    curl localhost:1234

Web Server Configuration

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.

Server Block

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.

Location Block

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.

Limit_except Block

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.

Contact

Michael Graefen

Florian Sandel

Ole-Paul Heinzelmann

(back to top)

About

Implementation of a minimalistic webserver for ecole 42

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •