49 lines
1.5 KiB
Nginx Configuration File
49 lines
1.5 KiB
Nginx Configuration File
events {
|
|
worker_connections 1024;
|
|
}
|
|
|
|
http {
|
|
upstream phoenix_backend {
|
|
least_conn;
|
|
server phoenix1:4000 max_fails=3 fail_timeout=30s;
|
|
server phoenix2:4000 max_fails=3 fail_timeout=30s;
|
|
server phoenix3:4000 max_fails=3 fail_timeout=30s;
|
|
}
|
|
|
|
# Map to track which backend server a WebSocket connection should use
|
|
map $http_upgrade $connection_upgrade {
|
|
default upgrade;
|
|
'' close;
|
|
}
|
|
|
|
server {
|
|
listen 4000;
|
|
server_name localhost;
|
|
|
|
# WebSocket configuration
|
|
location /socket {
|
|
proxy_pass http://phoenix_backend;
|
|
proxy_http_version 1.1;
|
|
proxy_set_header Upgrade $http_upgrade;
|
|
proxy_set_header Connection $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;
|
|
|
|
# WebSocket timeout settings
|
|
proxy_read_timeout 86400;
|
|
proxy_send_timeout 86400;
|
|
}
|
|
|
|
# HTTP fallback for health checks
|
|
location / {
|
|
proxy_pass http://phoenix_backend;
|
|
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;
|
|
}
|
|
}
|
|
}
|