Skip to content

Commit df3019d

Browse files
author
Paul C
committed
Initial commit: WolfProxy - Rust nginx proxy replacement
Features: - Reads nginx sites-enabled configuration directly - Automatic SSL/TLS certificate pickup from nginx config - Load balancing with round-robin, IP hash, least connections, weighted - Full upstream support with health checking - SNI support for multiple SSL domains - HTTP/1.1 and HTTP/2 support - Proxy pass with header manipulation - Location block matching (prefix, exact, regex) - Rewrite and redirect rules (C) 2025 Wolf Software Systems Ltd
0 parents  commit df3019d

14 files changed

Lines changed: 3321 additions & 0 deletions

.codewolf/conversation_codewolf.json

Lines changed: 346 additions & 0 deletions
Large diffs are not rendered by default.

.gitignore

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/target
2+
Cargo.lock
3+
*.log
4+
*.bak
5+
.DS_Store
6+
*.swp
7+
*.swo
8+
*~

Cargo.toml

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
[package]
2+
name = "wolfproxy"
3+
version = "0.1.0"
4+
edition = "2021"
5+
description = "A Rust-based nginx proxy replacement that reads nginx configuration files"
6+
authors = ["Wolf Software Systems Ltd"]
7+
8+
[dependencies]
9+
# Web framework
10+
axum = { version = "0.7", features = ["macros", "http1", "http2"] }
11+
tokio = { version = "1", features = ["full"] }
12+
13+
# Logging
14+
tracing = "0.1"
15+
tracing-subscriber = { version = "0.3", features = ["env-filter"] }
16+
17+
# Error handling
18+
anyhow = "1"
19+
20+
# Tower middleware
21+
tower = { version = "0.4", features = ["util", "timeout", "retry", "load-shed", "limit"] }
22+
tower-http = { version = "0.4", features = ["fs", "trace", "cors", "compression-gzip"] }
23+
24+
# HTTP client for proxying
25+
hyper = { version = "1", features = ["full"] }
26+
hyper-util = { version = "0.1.19", features = ["full", "client-legacy"] }
27+
http-body-util = "0.1"
28+
29+
# Serialization
30+
serde = { version = "1", features = ["derive"] }
31+
toml = "0.8"
32+
33+
# TLS/SSL
34+
rustls = "0.23"
35+
tokio-rustls = "0.26"
36+
rustls-pemfile = "2"
37+
38+
# Utilities
39+
bytes = "1"
40+
tokio-util = { version = "0.7", features = ["io"] }
41+
mime_guess = "2"
42+
futures-util = "0.3"
43+
regex = "1"
44+
url = "2"
45+
rand = "0.8"
46+
dashmap = "6"
47+
arc-swap = "1"
48+
notify = "6"
49+
fnv = "1"
50+
glob = "0.3"
51+
52+
[[bin]]
53+
name = "wolfproxy"
54+
path = "src/main.rs"

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Wolf Software Systems Ltd
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 205 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,205 @@
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

build.sh

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
#!/bin/bash
2+
# WolfProxy Build Script
3+
# (C) 2025 Wolf Software Systems Ltd
4+
5+
set -e
6+
7+
echo "Building WolfProxy..."
8+
9+
# Check for cargo
10+
if ! command -v cargo &> /dev/null; then
11+
echo "Error: cargo not found. Please install Rust: https://rustup.rs"
12+
exit 1
13+
fi
14+
15+
# Build in release mode
16+
cargo build --release
17+
18+
echo ""
19+
echo "Build complete!"
20+
echo "Binary location: target/release/wolfproxy"
21+
echo ""
22+
echo "To run: ./target/release/wolfproxy"
23+
echo "To install as service: sudo ./install_service.sh"

copyfiles

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/bin/bash
2+
# Copy WolfProxy files to a remote server
3+
# (C) 2025 Wolf Software Systems Ltd
4+
5+
set -e
6+
7+
if [ "$#" -lt 1 ]; then
8+
echo "Usage: $0 <user@host> [remote_path]"
9+
echo "Example: $0 root@server.example.com /opt/wolfproxy"
10+
exit 1
11+
fi
12+
13+
REMOTE_HOST="$1"
14+
REMOTE_PATH="${2:-/opt/wolfproxy}"
15+
16+
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
17+
18+
# Check if binary exists
19+
if [ ! -f "$SCRIPT_DIR/target/release/wolfproxy" ]; then
20+
echo "Binary not found. Building..."
21+
cd "$SCRIPT_DIR"
22+
cargo build --release
23+
fi
24+
25+
echo "Copying WolfProxy to $REMOTE_HOST:$REMOTE_PATH..."
26+
27+
# Create remote directory
28+
ssh "$REMOTE_HOST" "mkdir -p $REMOTE_PATH"
29+
30+
# Copy files
31+
scp "$SCRIPT_DIR/target/release/wolfproxy" "$REMOTE_HOST:$REMOTE_PATH/"
32+
scp "$SCRIPT_DIR/wolfproxy.toml.example" "$REMOTE_HOST:$REMOTE_PATH/"
33+
scp "$SCRIPT_DIR/install_service.sh" "$REMOTE_HOST:$REMOTE_PATH/"
34+
scp "$SCRIPT_DIR/README.md" "$REMOTE_HOST:$REMOTE_PATH/"
35+
36+
# Copy config if it doesn't exist on remote
37+
ssh "$REMOTE_HOST" "[ -f $REMOTE_PATH/wolfproxy.toml ] || cp $REMOTE_PATH/wolfproxy.toml.example $REMOTE_PATH/wolfproxy.toml"
38+
39+
echo ""
40+
echo "Files copied successfully!"
41+
echo ""
42+
echo "To install as service, SSH to the server and run:"
43+
echo " cd $REMOTE_PATH"
44+
echo " sudo ./install_service.sh"

0 commit comments

Comments
 (0)