Nginx jako reverse proxy distribuuje provoz, terminuje SSL a přidává caching.
Reverse proxy¶
server { location / { proxy_pass http://127.0.0.1:3000; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; } }
Load balancing¶
upstream backend { least_conn; server 10.0.1.1:3000 weight=3; server 10.0.1.2:3000; } server { location / { proxy_pass http://backend; } }
WebSocket¶
location /ws/ { proxy_pass http://127.0.0.1:3000; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection “upgrade”; }
Caching + rate limiting¶
proxy_cache_path /tmp/cache keys_zone=c:10m max_size=1g; limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s; location /api/ { limit_req zone=api burst=20 nodelay; proxy_pass http://backend; proxy_cache c; proxy_cache_valid 200 30m; }
Reverse proxy = produkce¶
SSL terminace, load balancing, caching — vše v jednom.