Skip to content

Webserv is an HTTP server built from scratch in C++ that implements the HTTP/1.1 protocol and supports CGI for dynamic content handling. It leverages multiplexing to manage multiple client connections efficiently, providing a scalable and performant solution for serving web content.

License

Notifications You must be signed in to change notification settings

ZakariaElbouzkri/webserv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸš€ WebServer

License
C++
Performance
Latency

Nginx++ is a high-performance, low-latency HTTP server written in C++. Designed to handle a wide range of HTTP requests efficiently, it supports advanced features like CGI scripting, file uploads, and custom configurations. Built with a focus on speed and reliability. It also includes a default index page with a CGI script that allows users to test all supported HTTP requests directly from their browser.


✨ Features

  • High Performance: Optimized for speed and low latency, capable of handling thousands of concurrent connections.
  • HTTP/1.1 Protocol Support: Fully supports GET, POST, PUT, and DELETE requests.
  • CGI Support: Execute dynamic content generation using CGI scripts (e.g., Python, PHP, Perl).
  • File Uploads: Easily upload files with configurable storage locations.
  • Auto Indexing: Automatically generates directory listings for directories without an index file.
  • Custom Configuration: Flexible configuration via servIO.conf to tailor the server to your needs.
  • Dockerized: Easy deployment using Docker for seamless integration into any environment.

πŸš€ Why Choose WebServer?

⚑ High Performance

WebServer is built with performance in mind. It uses efficient I/O multiplexing and a lightweight architecture to ensure minimal latency and maximum throughput. Whether you're serving static files or executing CGI scripts, WebServer delivers blazing-fast responses.

πŸ•’ Low Latency

Thanks to its non-blocking design and optimized request handling, WebServer ensures low-latency responses even under heavy load. This makes it ideal for real-time applications and high-traffic websites.

πŸ› οΈ Ease of Use

With a simple configuration file (servIO.conf) and a default index page that includes a CGI script, WebServer is incredibly easy to set up and use. You can test all supported HTTP requests directly from your browser without needing external tools.

🐳 Docker Support

WebServer is fully Dockerized, making it easy to deploy in any environment. Whether you're running it locally or in the cloud, Docker ensures consistent and hassle-free deployment.


πŸ“‚ Directory Structure

nginx++/
β”œβ”€β”€ Dockerfile
β”œβ”€β”€ LICENSE
β”œβ”€β”€ Makefile
β”œβ”€β”€ main.cpp
β”œβ”€β”€ .dockerignore
β”œβ”€β”€ Configuration/
β”‚   β”œβ”€β”€ HTTP.cpp
β”‚   β”œβ”€β”€ HTTP.hpp
β”‚   β”œβ”€β”€ LocationConf.cpp
β”‚   β”œβ”€β”€ LocationConf.hpp
β”‚   β”œβ”€β”€ MainConf.cpp
β”‚   β”œβ”€β”€ MainConf.hpp
β”‚   β”œβ”€β”€ ServerConf.cpp
β”‚   β”œβ”€β”€ ServerConf.hpp
β”‚   └── servIO.conf
β”œβ”€β”€ Core/
β”‚   β”œβ”€β”€ Client.cpp
β”‚   β”œβ”€β”€ Client.hpp
β”‚   β”œβ”€β”€ CoreServer.cpp
β”‚   β”œβ”€β”€ CoreServer.hpp
β”‚   β”œβ”€β”€ Selector.hpp
β”‚   β”œβ”€β”€ Server.cpp
β”‚   └── Server.hpp
β”œβ”€β”€ Http/
β”‚   β”œβ”€β”€ CGI.cpp
β”‚   β”œβ”€β”€ DefaultPages.cpp
β”‚   β”œβ”€β”€ DefaultPages.hpp
β”‚   β”œβ”€β”€ DeleteRequest.cpp
β”‚   β”œβ”€β”€ DeleteRequest.hpp
β”‚   β”œβ”€β”€ GetRequest.cpp
β”‚   β”œβ”€β”€ GetRequest.hpp
β”‚   β”œβ”€β”€ IRequest.hpp
β”‚   β”œβ”€β”€ MethodsUtils.cpp
β”‚   β”œβ”€β”€ PostRequest.cpp
β”‚   β”œβ”€β”€ PostRequest.hpp
β”‚   β”œβ”€β”€ ProcessRequest.cpp
β”‚   β”œβ”€β”€ ProcessRequest.hpp
β”‚   β”œβ”€β”€ PutRequest.cpp
β”‚   β”œβ”€β”€ PutRequest.hpp
β”‚   β”œβ”€β”€ Response.cpp
β”‚   β”œβ”€β”€ Response.hpp
β”‚   └── ResponseUtils.cpp
β”œβ”€β”€ Parser/
β”‚   β”œβ”€β”€ Lexer.cpp
β”‚   β”œβ”€β”€ Lexer.hpp
β”‚   β”œβ”€β”€ Parser.cpp
β”‚   β”œβ”€β”€ Parser.hpp
β”‚   β”œβ”€β”€ Token.cpp
β”‚   └── Token.hpp
β”œβ”€β”€ includes/
β”‚   └── Constants.hpp
β”œβ”€β”€ utils/
β”‚   β”œβ”€β”€ utils.cpp
β”‚   └── utils.hpp
└── www/
    β”œβ”€β”€ image/
    β”œβ”€β”€ media/
    └── other/
        β”œβ”€β”€ main.cpp
        └── test.txt

πŸ› οΈ Getting Started

Prerequisites

  • C++ Compiler (GCC or Clang)
  • Make
  • Docker (optional, for containerized deployment)

πŸš€ Running the Server Without Docker

  1. Clone the repository:

    git clone https://github.com/abizyane/WebServer.git
    cd WebServer
  2. Build the Server: Use the Makefile to compile the server:

    make
  3. Run the Server: Start the server using the compiled binary:

    ./nginx++
  4. Access the Server: Open your browser or use curl to access the server at http://localhost:8080.


🐳 Running the Server With Docker

  1. Build and Run the Docker Container: Use the Makefile to build and start the server:

    make up

    This will:

    • Build the Docker image.
    • Start the container and expose ports 8080, 5500, and 3333.
  2. Stop the Server: To stop the server, run:

    make down
  3. Restart the Server: To restart the server, run:

    make dc_re

πŸ§ͺ Testing the Server

Default Index Page with CGI Testing Interface

The server includes a default index page that features a CGI-powered interface. This interface allows you to test all supported HTTP requests (GET, POST, PUT, DELETE) directly from your browser. Simply navigate to http://localhost:8080/ and use the interactive form to send requests and view responses.

Example Requests

  1. GET Request: Fetch the default page:

    curl http://localhost:8080/
  2. Auto Indexing: If the directory has no index file, the server will generate an auto-indexed page. For example:

    curl http://localhost:8080/www/
  3. CGI Script: Execute a CGI script (e.g., app.py):

    curl http://localhost:8080/www/scripts/app.py

βš™οΈ Configuration

The server configuration is defined in Configuration/servIO.conf. You can modify this file to change server settings such as ports, root directories, and allowed methods.

Example configuration:

http {
    root /Webserv/www/;
    allow GET POST DELETE PUT;
    upload_store /Upload;
    server {
        listen 5500;
        listen 8080;
        server_name localhost;
        location / {
            error_page 404 404.html;
            cgi 0.0.0.0:90;
            autoindex on;
            index indexxx.html app.py;
            client_body_max_size 300;
            cgi .py .js .php .pl;
        }
        location /www/scripts {
            root /Webserv/www/scripts;
            autoindex on;
            cgi .py;
        }
        location /blog {
            deny DELETE;
        }
        location /container_rootdir {
            deny POST;
            deny DELETE;
            deny PUT;
            root /;
            autoindex on;
        }
    }
    server {
        listen 3333;
        location / {
            return 301 http://localhost:8080;
        }
    }
}

πŸ“œ License

This project is licensed under the MIT License - see the LICENSE file for details.


πŸ‘ Acknowledgments

  • Zakaria El Bouzkri πŸ§‘β€πŸ’»
  • Achraf Bizyane πŸ§‘β€πŸ’»
  • Noureddine Akebli πŸ§‘β€πŸ’»

🌟 Inspired By

  • The simplicity and performance of Nginx.
  • The power of C++.

About

Webserv is an HTTP server built from scratch in C++ that implements the HTTP/1.1 protocol and supports CGI for dynamic content handling. It leverages multiplexing to manage multiple client connections efficiently, providing a scalable and performant solution for serving web content.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •