Skip to content

Asynchronous web server written in Rust, inspired by NGINX.

Notifications You must be signed in to change notification settings

iibabyy/Rust-webserv

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

83 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Rust Web Server

A high-performance web server implemented in Rust, inspired by nginx's architecture and features.

Features

Core Functionality

  • HTTP/1.1 protocol support
  • Keep-alive connection handling
  • Asynchronous I/O using Tokio
  • Configurable server blocks
  • Multiple server support (virtual hosting)

Request Handling

  • Support for GET and POST methods
  • Content-Length validation
  • Maximum body size limits
  • Custom error pages and redirects

Static File Serving

  • Directory listing with auto-indexing
  • Custom index file configuration
  • Root directory configuration
  • Stylish auto-generated directory listings with gradient backgrounds

CGI Support

  • Dynamic content generation through CGI scripts
  • CGI environment variable handling
  • Request body forwarding to CGI scripts
  • Configurable CGI extensions and paths

Location Blocks

  • Path-based configuration blocks
  • Alias support
  • Internal location handling
  • Custom routing rules

Configuration

  • Server name configuration
  • Port binding configuration
  • Upload folder specification
  • Client max body size limits
  • Multiple methods restriction
  • Custom error pages
  • Return directives for redirects

Error Handling

  • Comprehensive error reporting
  • Custom error page mapping
  • Error redirects with status codes
  • Graceful connection handling

Configuration Example

server {
    listen 8080;
    server_name example.com;
    root /var/www/html;
    
    client_max_body_size 10M;
    auto_index on;
    
    location /uploads {
        upload_folder /var/www/uploads;
        methods GET POST;
    }
    
    location /cgi-bin {
        cgi .php /usr/bin/php-cgi;
    }
}

Quick Start

Prerequisites

  • Cargo

Run

unzip URIs
cargo run --release

Performances

This test is not very scientific and was simply a small experiment to see roughly how my web server is performing

bombardier http://localhost:8080/ -c 1000 --latencies --fasthttp -H "Connection
: Close"
Bombarding http://localhost:8080/ for 10s using 1000 connection(s)
[========================================================================================================================] 10s
Done!
Statistics        Avg      Stdev        Max
  Reqs/sec     10256.26    2923.56   19914.07
  Latency       97.03ms    30.06ms   511.95ms
  Latency Distribution
     50%    93.78ms
     75%   108.64ms
     90%   124.37ms
     95%   136.59ms
     99%   181.70ms
  HTTP codes:
    1xx - 0, 2xx - 103328, 3xx - 0, 4xx - 0, 5xx - 0
    others - 0

About

Asynchronous web server written in Rust, inspired by NGINX.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published