Basic Proxy
A simple reverse proxy example forwarding HTTP requests to a backend.
Configuration
Runtime Config (config.yaml)
yaml
http:
- "0.0.0.0:8080"
config_dir: "./config"
pingora:
daemon: false
threads: 4
work_stealing: trueProxy Config (config/proxy.yaml)
yaml
services:
- name: backend
service_type: http
algorithm: round_robin
endpoints:
- ip: 127.0.0.1
port: 3000
routes:
- route:
type: host
value: localhost
name: default
paths:
- path:
- /
- /{*path}
service:
name: backendRunning
bash
nylon run -c config.yamlTesting
bash
# Make a request
curl http://localhost:8080
# With headers
curl -H "X-Custom-Header: value" http://localhost:8080/api
# POST request
curl -X POST -d '{"key":"value"}' \
-H "Content-Type: application/json" \
http://localhost:8080/apiMultiple Backends
Add more endpoints for load balancing:
yaml
services:
- name: backend
service_type: http
algorithm: round_robin
endpoints:
- ip: 127.0.0.1
port: 3000
- ip: 127.0.0.1
port: 3001
- ip: 127.0.0.1
port: 3002Health Checks
Enable health checking:
yaml
services:
- name: backend
service_type: http
algorithm: round_robin
endpoints:
- ip: 127.0.0.1
port: 3000
- ip: 127.0.0.1
port: 3001
health_check:
enabled: true
path: /health
interval: 5s
timeout: 2s
healthy_threshold: 2
unhealthy_threshold: 3Path-Based Routing
Route different paths to different services:
yaml
services:
- name: api-service
service_type: http
algorithm: round_robin
endpoints:
- ip: 127.0.0.1
port: 3000
- name: admin-service
service_type: http
algorithm: round_robin
endpoints:
- ip: 127.0.0.1
port: 4000
routes:
- route:
type: host
value: localhost
name: default
paths:
- path: /api/{*path}
service:
name: api-service
- path: /admin/{*path}
service:
name: admin-serviceHost-Based Routing
Route by hostname:
yaml
services:
- name: app1-service
service_type: http
algorithm: round_robin
endpoints:
- ip: 127.0.0.1
port: 3000
- name: app2-service
service_type: http
algorithm: round_robin
endpoints:
- ip: 127.0.0.1
port: 4000
routes:
- route:
type: host
value: app1.example.com
name: app1
paths:
- path:
- /
- /{*path}
service:
name: app1-service
- route:
type: host
value: app2.example.com
name: app2
paths:
- path:
- /
- /{*path}
service:
name: app2-service