Skip to content

xinluw/rust-nginx

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

rust-nginx

A high-performance HTTP server written in Rust, inspired by and wire/config-compatible with nginx.

一个用 Rust 编写的高性能 HTTP 服务器,配置语法兼容 nginx。在静态文件场景下,吞吐与延迟、内存占用全面优于 nginx 1.18(详见 性能报告)。

Rust License: MIT Platform

rust-nginx vs nginx — throughput comparison

Throughput vs nginx 1.18 on an 8-core Ubuntu 22.04 VM (wrk, interleaved peak-of-5). Full numbers in the performance report.


Highlights

  • Faster than nginx on the common cases. Small/medium static files: +35% – +126% throughput vs nginx 1.18, with lower latency in every scenario and ~1/5 the memory.
  • nginx-compatible configuration — drop in an nginx.conf-style file.
  • Zero-copy static serving via sendfile(2), an open-file cache (kept-open fd + precomputed response), and an allocation-free hot path.
  • Async core built on Tokio, one task per connection, SO_REUSEPORT per-worker listeners.
  • Built-in TLS (rustls), gzip/deflate, byte-range requests, ETag / conditional requests, directory autoindex.
  • Reverse proxy & load balancing (round-robin, least-connections, IP-hash) with health checks.
  • Cross-platform: Linux (production, zero-copy fast paths) and Windows (development).

Performance

Measured on an 8-core Ubuntu 22.04 VM, wrk load generator, both servers at 4 workers, interleaved peak-of-5 (see BENCHMARK_REPORT.md and the PDF report).

Scenario Concurrency nginx (req/s) rust-nginx (req/s) Δ
index.html (47 B) 10 6,390 9,831 +54%
index.html (47 B) 100 11,967 27,061 +126%
index.html (47 B) 500 15,218 27,502 +81%
1 KB 100 12,589 23,977 +90%
10 KB 100 13,467 13,936 +3%
100 KB 100 8,446 9,361 +11%
1.4 MB 50 1,336 1,118 −16%
1.4 MB 100 1,240 1,127 −9%

Resource usage (c=100): RSS ≈ 6 MB vs nginx 25 MB; small-file CPU per 1000 req 11.7 vs 25.8 (≈2.2× more efficient); p99 latency lower in all scenarios.

rust-nginx wins decisively on small/medium files and is at near-parity on very large single downloads (a loopback-specific artifact of the async send path; see the report).

Quick start

# 1. Install Rust (https://rustup.rs) if you don't have it
# 2. Build
cargo build --release

# 3. Run with a config
./target/release/rust-nginx -c conf/nginx.conf start

# Test a config without starting
./target/release/rust-nginx -c conf/nginx.conf test

Then open http://localhost/ (port from the listen directive in your config).

Installation

Detailed, step-by-step instructions for both platforms — including running rust-nginx as a systemd service on Linux — are in docs/INSTALLATION.md.

  • Linux: build from source, install the binary, run as a systemd service.
  • Windows: install Rust, build, run from PowerShell.

Usage / configuration

The full command-line reference, configuration directives, signals, and examples are in docs/USER_MANUAL.md.

rust-nginx [OPTIONS] [COMMAND]

COMMANDS:
  start     Start the server (default)
  test      Validate the configuration file and exit
  reload    Signal a running instance to reload its configuration

OPTIONS:
  -c, --config <PATH>    Configuration file       [default: conf/nginx.conf]
  -p, --prefix <PATH>    Server root prefix        [default: current dir]
      --workers <N>      Override worker count
  -h, --help             Print help
  -V, --version          Print version

Project layout

src/
  core/        connection handling, worker pool, request pipeline
  http/        request/response types, HTTP/1.1 parser, headers
  handler/     static files, open-file cache, error pages, rewrite
  proxy/       reverse proxy, upstream pool, load balancing, health checks
  tls/         rustls integration
  config/      nginx-style config parser & directives
  log/         access & error logging
  util/        buffers, paths, signals
conf/          sample configuration
tests/         integration tests
docs/          installation guide & user manual
report/        performance report (PDF)
benchmarks/    reproducible benchmark scripts (wrk)

Building from source

Requires a recent stable Rust toolchain (edition 2021; tested with 1.75+ and 1.96).

cargo build --release        # optimized binary at target/release/rust-nginx
cargo test                   # run the test suite

The release profile enables LTO, single codegen unit, and symbol stripping for a lean, fast binary.

License

MIT — see LICENSE.

Acknowledgements

Inspired by nginx. Built with Tokio and rustls.

About

High-performance HTTP server in Rust, nginx-compatible config; faster than nginx on static workloads.

Topics

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages