map $http_upgrade $proxy_connection { default "rpc_backend${RPC_PATH}"; websocket "ws_backend${WS_PATH}"; } server { listen 80; server_name _; location / { proxy_pass http://$proxy_connection; proxy_set_header Host $host; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Proto $scheme; } } upstream rpc_backend { server ${PROXY_HOST}:${RPC_PORT}; } upstream ws_backend { server ${PROXY_HOST}:${WS_PORT}; }