Documentation to configure nginx to work with websockets #663

Closed
Chipairon opened this Issue Mar 6, 2015 · 1 comment

Projects

None yet

2 participants

@Chipairon

Hi,
In order to work with websockets proxying the application behind nginx, this configuration is needed to avoid 400 responses on connection negotiation:

map $http_upgrade $connection_upgrade {
  default upgrade;
  ''      close;
}
server{
  listen 80;
  server_name <your.domain>;

  location / {
    proxy_pass http://localhost:<port>;
    proxy_set_header X-Real-IP $remote_addr;  # http://wiki.nginx.org/HttpProxyModule
    proxy_set_header Host $host;  # pass the host header - http://wiki.nginx.org/HttpProxyModule#proxy_pass
    proxy_http_version 1.1;  # recommended with keepalive connections - http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_http_version
    # WebSocket proxying - from http://nginx.org/en/docs/http/websocket.html
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection $connection_upgrade;
  }
}

I am not sure if this should be added to the guides about advanced deployment or channels so I am posting it here.

Cheers

@josevalim
Member

Thank you @Chipairon! The best is if you could write a blog post, as it would be the most googleable way (I think). In any case, we appreciate the info!

@josevalim josevalim closed this Mar 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment