yurko

yurko

Phoenix WebSocket behind proxy

Recently we had a bug report from the client that states they are unable to connect to WebSocket with Error during WebSocket Handshake: 'Connection' header value must contain 'Upgrade'.

Obviously we have this header so the only thing I can think of is that ours is downcased (people seem to have problems with that).

For this reason I wanted to capitalize “Upgrade” in the “Connection” header, but it’s trickier then it seems: When I run locally and analyze headers I can see that it is already capitalized, but behind the proxy it becomes downcase.

In nginx I capitalized the proxy_set_header Connection value which does nothing. I then tried both add_header Connection "Upgrade" always; and more_set_headers 'Connection: Upgrade'; from headers-more-nginx module, they work but add an extra “Connection” header instead of modifying the existing one which doesn’t seem solve the problem.

I also tried to clear the existing header before setting the new one, things like more_clear_headers 'Connection'; and such but they seem to “miss” the downcased header as if it didn’t exist.

Did anyone have a similar problem? Any info on how exactly the whole thing works? ideas how to solve it?

As I understand it headers go in, get proxied to the app and get downcased on their way back without much control over the whole thing.

At the moment I’m thinking about dropping nginx and using cap_net_bind_service or iptables to get to port 80 but I hope there is an easier solution.

Marked As Solved Switch mode

yurko

yurko

It’s not an nginx issue after all, there seem to be a well hidden firewall that messes up port 80 traffic on the application level. Using another port (incl. wss with 443) solves the issue and 80 wouldn’t work with nginx or directly.

Sorry for the confusion and thanks for all your feedback!

Also Liked

rms.mrcs

rms.mrcs

Here is my nginx proxy that I use in production for a Socket.IO server:

location /socket.io {
        proxy_pass http://localhost:8890;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;
}

I have this working for a year, already. Hope it helps.

OvermindDL1

OvermindDL1

Which are precisely? We might be able to test here. :slight_smile:

Last Post!

yurko

yurko

I’m afraid I can’t tell you much on this topic, it should have been a part of network setup since no one was aware of it and we had to exclude every other option and basically “prove” that something happens on the network level for it to come up.

Anyway I don’t think it’s something to worry about in the long run since it messes up all WS traffic on port 80, so at some point it will be removed or updated.

Where Next?

Trending in Questions Top

jonnycharles
I’m in search of an Elixir library that offers PDF generation capabilities similar to Ruby’s Prawn. While there have been discussions abo...
New
spammy
I’m looking to build a personal workflow to quickly deploy web applications written in elixir/phoenix, for local consumption (ie not on t...
New
silverdr
Using Phoenix.LiveView.TagEngine as an EEx.Engine is deprecated! To compile HEEx, use Phoenix.LiveView.TagEngine.compile/2 instead. Sta...
New
saveman71
Hello ! We want new/edit form pages to POST/PUT to their own URL rather than the resources REST defaults (post /things, put /things/:id)...
New
dli
Before I dive in myself, did anyone successfully sprinkle Hologram into their existing LiveView app? Looking for hints regarding: Addi...
New
bottlenecked
Hi all, I wanted to ask how the community is dealing with post-release steps. Today we have Ecto migrations, which make sure that the db...
New
michallepicki
I am using Oban and occasionally, shortly after a deployment, a handful of jobs can fail because of dependency on other parts of the syst...
New

Other Trending Topics Top

JesseHerrick
Hey, I’m Jesse and I’m the main contributor behind Dexter, a full-featured, lightning-fast Elixir LSP optimized for large codebases. It s...
New
jimsynz
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve. They are GUI (Emerge) and State management (S...
New
ausimian
Emily is an Elixir library that runs Nx computations on Apple’s MLX. Install it as the default Nx backend and Nx, defn, Axon, Nx.Serving,...
New
type1fool
I just stumbled on a newly redesigned elixir-lang.org. :tada: It looks like @Software_Mansion did the work, and I think it is generally a...
New
akoutmos
@hugobarauna and I (Alex Koutmos) have been hard at work on writing a book on Nerves that takes you from simply blinking LEDs to building...
New

We're in Beta

About us Mission Statement