# Include in http {}. Configure TLS before exposing this site to the internet. map $http_upgrade $example_ws_connection { default upgrade; '' close; } limit_conn_zone $binary_remote_addr zone=example_ws_clients:1m; server { listen 80; server_name chat.example; location = /ws { limit_conn example_ws_clients 10; limit_conn_status 429; proxy_pass http://127.0.0.1:8081; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $example_ws_connection; proxy_set_header Host $host; proxy_set_header X-Forwarded-Host $host; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Proto $scheme; proxy_set_header X-Real-IP $remote_addr; proxy_set_header Forwarded ""; # The upstream should send pings more often than this idle timeout. proxy_read_timeout 90s; } location / { return 404; } }