Docs / Web Servers / How to Configure Nginx for WebSocket Support

How to Configure Nginx for WebSocket Support

By Admin · Feb 25, 2026 · Updated Apr 23, 2026 · 68 views · 1 min read

WebSocket connections require specific Nginx proxy configuration.

Configuration

server {\n    listen 80;\n    server_name ws.example.com;\n\n    location / {\n        proxy_pass http://127.0.0.1:3000;\n        proxy_http_version 1.1;\n        proxy_set_header Upgrade $http_upgrade;\n        proxy_set_header Connection "upgrade";\n        proxy_set_header Host $host;\n        proxy_set_header X-Real-IP $remote_addr;\n        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;\n        proxy_read_timeout 86400;\n    }\n}

Key Settings

  • proxy_http_version 1.1 — Required for WebSocket
  • Upgrade and Connection headers — Enable protocol switch
  • proxy_read_timeout — Prevent Nginx from closing idle WebSocket connections

Was this article helpful?