upstream phoenix_backend { hash $http_sec_websocket_key consistent; server phoenix1:4000 max_fails=1 fail_timeout=10s; server phoenix2:4000 max_fails=1 fail_timeout=10s; server phoenix3:4000 max_fails=1 fail_timeout=10s; } server { listen 80; server_name localhost; location /socket { proxy_pass http://phoenix_backend; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection "upgrade"; 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; proxy_next_upstream error timeout invalid_header http_502 http_503 http_504; proxy_next_upstream_tries 1; proxy_connect_timeout 1s; } location /api { proxy_pass http://phoenix_backend; proxy_http_version 1.1; 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; proxy_next_upstream error timeout invalid_header http_502 http_503 http_504; proxy_next_upstream_tries 3; proxy_connect_timeout 5s; proxy_read_timeout 30s; } location /health { access_log off; return 200 "healthy\n"; add_header Content-Type text/plain; } }