|
| 1 | +# WolfProxy |
| 2 | + |
| 3 | +A high-performance Rust-based reverse proxy server that reads and uses nginx configuration files directly. |
| 4 | + |
| 5 | +**(C) 2025 Wolf Software Systems Ltd - http://wolf.uk.com** |
| 6 | + |
| 7 | +## Features |
| 8 | + |
| 9 | +- **Drop-in nginx replacement**: Reads nginx sites-enabled configuration directly |
| 10 | +- **Automatic SSL/TLS**: Automatically picks up SSL certificates from nginx config (Let's Encrypt, etc.) |
| 11 | +- **Load Balancing**: Full upstream support with multiple algorithms: |
| 12 | + - Round Robin |
| 13 | + - Weighted Round Robin |
| 14 | + - IP Hash (sticky sessions) |
| 15 | + - Least Connections |
| 16 | + - Random |
| 17 | +- **Health Checking**: Automatic backend health monitoring with configurable thresholds |
| 18 | +- **SNI Support**: Proper Server Name Indication for multiple SSL domains |
| 19 | +- **HTTP/1.1 & HTTP/2**: Full protocol support |
| 20 | + |
| 21 | +## Supported nginx Directives |
| 22 | + |
| 23 | +### Server Block |
| 24 | +- `listen` - Port and SSL configuration |
| 25 | +- `server_name` - Virtual host names |
| 26 | +- `root` - Document root |
| 27 | +- `index` - Index files |
| 28 | +- `error_page` - Custom error pages |
| 29 | +- `ssl_certificate` / `ssl_certificate_key` - SSL certificates |
| 30 | +- `include` - Include other config files |
| 31 | +- `gzip` - Compression (header support) |
| 32 | + |
| 33 | +### Location Block |
| 34 | +- `location` - Path matching (prefix, exact `=`, regex `~`, case-insensitive `~*`, priority `^~`) |
| 35 | +- `proxy_pass` - Reverse proxy to backend or upstream |
| 36 | +- `proxy_set_header` - Set headers for backend |
| 37 | +- `proxy_http_version` - HTTP version for backend |
| 38 | +- `proxy_buffer_size` / `proxy_buffers` - Buffer configuration |
| 39 | +- `proxy_connect_timeout` / `proxy_read_timeout` / `proxy_send_timeout` - Timeouts |
| 40 | +- `root` / `alias` - Static file serving |
| 41 | +- `try_files` - Try multiple files |
| 42 | +- `return` - Return status codes or redirects |
| 43 | +- `rewrite` - URL rewriting |
| 44 | +- `deny` / `allow` - Access control |
| 45 | +- `add_header` - Add response headers |
| 46 | + |
| 47 | +### Upstream Block |
| 48 | +- `upstream` - Define backend server groups |
| 49 | +- `server` - Backend servers with options: |
| 50 | + - `weight` - Server weight |
| 51 | + - `max_fails` - Failure threshold |
| 52 | + - `fail_timeout` - Recovery timeout |
| 53 | + - `backup` - Backup server |
| 54 | + - `down` - Mark server as down |
| 55 | +- `ip_hash` - Sticky sessions |
| 56 | +- `least_conn` - Least connections balancing |
| 57 | +- `keepalive` - Connection pooling |
| 58 | + |
| 59 | +### Conditionals |
| 60 | +- `if ($host = ...)` - Host-based conditions |
| 61 | +- `if ($request_method = ...)` - Method-based conditions |
| 62 | + |
| 63 | +## Installation |
| 64 | + |
| 65 | +### Prerequisites |
| 66 | + |
| 67 | +- Rust 1.70+ (https://rustup.rs) |
| 68 | +- Existing nginx configuration in `/etc/nginx/sites-enabled/` |
| 69 | + |
| 70 | +### Build |
| 71 | + |
| 72 | +```bash |
| 73 | +./build.sh |
| 74 | +``` |
| 75 | + |
| 76 | +Or manually: |
| 77 | + |
| 78 | +```bash |
| 79 | +cargo build --release |
| 80 | +``` |
| 81 | + |
| 82 | +### Run |
| 83 | + |
| 84 | +```bash |
| 85 | +./run.sh |
| 86 | +``` |
| 87 | + |
| 88 | +Or: |
| 89 | + |
| 90 | +```bash |
| 91 | +./target/release/wolfproxy |
| 92 | +``` |
| 93 | + |
| 94 | +### Install as Service |
| 95 | + |
| 96 | +```bash |
| 97 | +sudo ./install_service.sh |
| 98 | +``` |
| 99 | + |
| 100 | +This will: |
| 101 | +1. Copy the binary to `/opt/wolfproxy/` |
| 102 | +2. Create a systemd service |
| 103 | +3. Optionally stop nginx and start WolfProxy |
| 104 | + |
| 105 | +## Configuration |
| 106 | + |
| 107 | +WolfProxy uses a simple TOML configuration file (`wolfproxy.toml`): |
| 108 | + |
| 109 | +```toml |
| 110 | +[server] |
| 111 | +host = "0.0.0.0" |
| 112 | +http_port = 80 |
| 113 | +https_port = 443 |
| 114 | + |
| 115 | +[nginx] |
| 116 | +config_dir = "/etc/nginx" |
| 117 | +auto_reload = false |
| 118 | +``` |
| 119 | + |
| 120 | +The nginx configuration is read from: |
| 121 | +- `{config_dir}/sites-enabled/` - Site configuration files |
| 122 | +- `{config_dir}/conf.d/*.conf` - Additional configuration files |
| 123 | + |
| 124 | +## Example nginx Configuration |
| 125 | + |
| 126 | +WolfProxy will read standard nginx configuration like: |
| 127 | + |
| 128 | +```nginx |
| 129 | +upstream backend { |
| 130 | + ip_hash; |
| 131 | + server 10.0.10.105 max_fails=3 fail_timeout=360s; |
| 132 | + server 10.0.10.102 max_fails=3 fail_timeout=360s; |
| 133 | + server 10.0.10.103 max_fails=3 fail_timeout=360s; |
| 134 | +} |
| 135 | +
|
| 136 | +server { |
| 137 | + listen 80; |
| 138 | + listen [::]:80; |
| 139 | + server_name example.com; |
| 140 | +
|
| 141 | + location / { |
| 142 | + return 301 https://$host$request_uri; |
| 143 | + } |
| 144 | +} |
| 145 | +
|
| 146 | +server { |
| 147 | + listen 443 ssl; |
| 148 | + listen [::]:443 ssl; |
| 149 | + server_name example.com; |
| 150 | +
|
| 151 | + ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem; |
| 152 | + ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem; |
| 153 | +
|
| 154 | + location / { |
| 155 | + proxy_pass http://backend; |
| 156 | + proxy_set_header Host $http_host; |
| 157 | + proxy_set_header X-Real-IP $remote_addr; |
| 158 | + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; |
| 159 | + proxy_set_header X-Forwarded-Proto $scheme; |
| 160 | + proxy_http_version 1.1; |
| 161 | + proxy_set_header Connection ""; |
| 162 | + } |
| 163 | +} |
| 164 | +``` |
| 165 | + |
| 166 | +## Migration from nginx |
| 167 | + |
| 168 | +1. **Stop nginx**: `sudo systemctl stop nginx` |
| 169 | +2. **Install WolfProxy**: `sudo ./install_service.sh` |
| 170 | +3. **Start WolfProxy**: `sudo systemctl start wolfproxy` |
| 171 | +4. **Verify**: Check your sites are working |
| 172 | +5. **Disable nginx**: `sudo systemctl disable nginx` |
| 173 | +6. **Enable WolfProxy**: `sudo systemctl enable wolfproxy` |
| 174 | + |
| 175 | +## Logging |
| 176 | + |
| 177 | +Set the `RUST_LOG` environment variable to control log level: |
| 178 | + |
| 179 | +```bash |
| 180 | +RUST_LOG=debug ./target/release/wolfproxy |
| 181 | +``` |
| 182 | + |
| 183 | +Levels: `trace`, `debug`, `info`, `warn`, `error` |
| 184 | + |
| 185 | +## Comparison with nginx |
| 186 | + |
| 187 | +| Feature | nginx | WolfProxy | |
| 188 | +|---------|-------|-----------| |
| 189 | +| Configuration | nginx native | nginx native (reads directly) | |
| 190 | +| Memory Usage | Low | Very Low | |
| 191 | +| Performance | Excellent | Excellent | |
| 192 | +| SSL/TLS | Yes | Yes (auto-detect from config) | |
| 193 | +| HTTP/2 | Yes | Yes | |
| 194 | +| Load Balancing | Yes | Yes | |
| 195 | +| Lua Scripting | Yes | No | |
| 196 | +| Module System | Yes | No (but extensible in Rust) | |
| 197 | + |
| 198 | +## License |
| 199 | + |
| 200 | +MIT License - See LICENSE file |
| 201 | + |
| 202 | +## Support |
| 203 | + |
| 204 | +- Website: http://wolf.uk.com |
| 205 | +- Issues: GitHub Issues |
0 commit comments