Skip to content

Documentation to configure nginx to work with websockets #663

Closed

Description

@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

Activity

  1. josevalim commented on Mar 6, 2015

    @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!

  2. acrolink commented on Oct 6, 2017

    @acrolink

    @chipairon, thank you very much. @josevalim, keep up the great work.

  3. hopewise commented on Mar 28, 2020

    @hopewise

    @josevalim I've been struggling with using SSL with phoenix directly, I found using nginx much more easier. I wish it was that easy with phoenix, so that I don't have to use nginx as a proxy..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions