Skip to main content
Version: 3.x

Behind a reverse proxy

You will find below the configuration needed for deploying a Socket.IO server behind a reverse-proxy solution, such as:

In a multi-server setup, please check the documentation here.


Content of /etc/nginx/nginx.conf:

http {
server {
listen 80;

location / {
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;

proxy_pass http://localhost:3000;

proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";


Apache HTTPD

Content of /usr/local/apache2/conf/httpd.conf:

Listen 80


LoadModule mpm_event_module modules/

LoadModule authn_file_module modules/
LoadModule authn_core_module modules/
LoadModule authz_host_module modules/
LoadModule authz_groupfile_module modules/
LoadModule authz_user_module modules/
LoadModule authz_core_module modules/

LoadModule headers_module modules/
LoadModule lbmethod_byrequests_module modules/
LoadModule proxy_module modules/
LoadModule proxy_balancer_module modules/
LoadModule proxy_http_module modules/
LoadModule proxy_wstunnel_module modules/
LoadModule rewrite_module modules/
LoadModule slotmem_shm_module modules/
LoadModule unixd_module modules/

User daemon
Group daemon

ProxyPass / http://localhost:3000/
RewriteEngine on
RewriteCond %{HTTP:Upgrade} websocket [NC]
RewriteCond %{HTTP:Connection} upgrade [NC]
RewriteRule ^/?(.*) "ws://localhost:3000/$1" [P,L]

ProxyTimeout 3


Node.js http-proxy

Installation: npm i http-proxy

const httpProxy = require("http-proxy");

target: "http://localhost:3000",
ws: true,


Caddy 2

Content of Caddyfile for Caddy 2 {
rewrite /path /path/
handle /path/* {
uri strip_prefix /path
rewrite * /{path}
reverse_proxy localhost:3000 {
header_up Host {host}
header_up X-Real-IP {remote}