Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation to configure nginx to work with websockets #663

Closed
chipairon opened this issue Mar 6, 2015 · 3 comments
Closed

Documentation to configure nginx to work with websockets #663

chipairon opened this issue Mar 6, 2015 · 3 comments

Comments

@chipairon
Copy link

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
Copy link
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!

@acrolink
Copy link

acrolink commented Oct 6, 2017

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

@hopewise
Copy link

hopewise commented Mar 28, 2020

@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
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants