tommaso

tommaso

Issue with LiveView using Dokku – websocket failing

Hello Folks!

I am deploying a small test project using Dokku and DigitalOcean, but I’m not able to get the LiveView working properly even after two days of experiments. I followed the steps as described in Deploy a Phoenix app with Dokku and Digital Ocean | AV with few tweaks on the elixir/erlang versions, and I’m using the default Esbuild.

The problem seems related to how Nginx is configured but even following these instructions NGINX | F5 the websocket connection is still failing.

The issue might be somewhere else, maybe you can point me in the right direction. Below you find the error I get by enabling liveSocket.enableDebug() which you can also check at this URL https://evepeak.com/enduro-time

app-43225e7c9981857a04b1c349ea5eb174.js?vsn=d:1 WebSocket connection to 'wss://evepeak.com/live/websocket?_csrf_token=LG8SLy5zKx0BFlg9dwU8DQc9Gx07Ij0Lm5PaVCAtHP4Z5on8HDKZXJNQ&_track_static%5B0%5D=https%3A%2F%2Fevepeak.com%2Fassets%2Fapp-12403e086a772b88f325d7f94661e032.css%3Fvsn%3Dd&_track_static%5B1%5D=https%3A%2F%2Fevepeak.com%2Fassets%2Fapp-43225e7c9981857a04b1c349ea5eb174.js%3Fvsn%3Dd&_mounts=0&vsn=2.0.0' failed: 
connect @ app-43225e7c9981857a04b1c349ea5eb174.js?vsn=d:1
e @ app-43225e7c9981857a04b1c349ea5eb174.js?vsn=d:17
connect @ app-43225e7c9981857a04b1c349ea5eb174.js?vsn=d:17
(anonymous) @ app-43225e7c9981857a04b1c349ea5eb174.js?vsn=d:17
(anonymous) @ app-43225e7c9981857a04b1c349ea5eb174.js?vsn=d:17
app-43225e7c9981857a04b1c349ea5eb174.js?vsn=d:1 phx-FvDVpr_eT_6qxAah destroyed: the child has been removed from the parent -  undefined
app-43225e7c9981857a04b1c349ea5eb174.js?vsn=d:1 phx-FvDVpr_eT_6qxAah join: encountered 103 consecutive reloads -  undefined
app-43225e7c9981857a04b1c349ea5eb174.js?vsn=d:1 phx-FvDVpr_eT_6qxAah join: exceeded 10 consecutive reloads. Entering failsafe mode -  undefined
app-43225e7c9981857a04b1c349ea5eb174.js?vsn=d:1 phx-FvDVpr_eT_6qxAah error: view crashed -  undefined

This is my first post so thank you for having me here and sorry for jumping straight to a question.. I hope I can be useful too in the future..

Thanks a lot in advance!
Tommaso

Marked As Solved

egze

egze

Is nginx properly configured? I remember that I needed a file nginx.conf.sigil with something like this inside:

location ~ live/websocket {
    proxy_http_version 1.1;
    proxy_set_header Origin '';
    proxy_set_header X-Forwarded-Host $proxy_add_x_forwarded_for;
    proxy_set_header Upgrade $http_upgrade;
    proxy_set_header Connection "Upgrade";
    proxy_pass  http://{{ $.APP }}-{{ $upstream_port }};
    break;
  }

Also Liked

cmcaine

cmcaine

With dokku 0.27.1 there is no need to modify the nginx configuration. If your websocket fails to connect then you probably aren’t telling your app what domain name you’re using and so the check_origin check is failing.

You can confirm this by looking in the logs of your app for a line like “Could not check origin for Phoenix.Socket transport”.

dokku config:set your-app-name PHX_HOST=your-public-domain-name is probably all you need.

If you instead do proxy_set_header Origin ''; in the nginx file, you’re removing all origin checks, which is equivalent to setting check_origin: false. The docs advise against doing this:

If false, your app is vulnerable to Cross-Site WebSocket Hijacking (CSWSH) attacks. Only use in development, when the host is truly unknown or when serving clients that do not send the origin header, such as mobile apps.

The default liveview websockets use CSRF tokens, I think, so they’re probably not vulnerable, but it’s something to be careful about.

If your app uses liveview/websockets on multiple domains you will need to explicitly configure check_origin for your endpoint (this is the case whether or not you use dokku).

evadne

evadne

ws connection seems established, so possibly check_origin config issue causing the 403

tommaso

tommaso

Hi @egze, I did configure Nginx but I omitted the proxy_set_header Origin ... as @evadne suspected it was indeed an issue with check_origin configuration. I assumed it would be correctly set by the proxy but clearly it was not. After days of experiments now it’s solved! Thanks a lot to you all!

Where Next?

Popular in Questions Top

_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
JulienCorb
I am trying to implement my new.html.eex file to create new posts on my website. new.html.eex: <h1>Create Post</h1> <%= ...
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New
alice
Hey, Just curious what are the main benefits of Elixir compared to Clojure? When is Elixir more useful than Clojure and vice versa? Th...
New
vonH
When I run the Plug and I recompile I wind up having to use Ctrl C to quit iex and start again. Witht the help of rlwrap I can use the cu...
New
freewebwithme
Using vs code and installed ElixirLS: support and debugger. And I got an error popped up on start up says Failed to run ‘elixir’ comma...
New
Qqwy
Original source of discussion: This topic on the Pragmatic Programmers’ Functional Web Development with Elixir, OTP, and Phoenix forum. ...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
hariharasudhan94
I would like to know what is the best IDE for elixir development?
New

Other popular topics Top

senggen
Erlang/OTP 25 [erts-13.2.2] [source] [64-bit] [smp:8:8] [ds:8:8:10] [async-threads:1] 15:22:35.803 [error] gen_event {lager_file_backend...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
johnnyicon
Hi all, I’ve just started learning Elixir and Phoenix Framework, so please pardon my n00bness at this stage. I’m trying to use Postgres...
New
chrismccord
This release brings a number of exciting features, including integration with the new Phoenix LiveDashboard and Phoenix LiveView. There h...
New
JorisKok
I have a server on AWS, and was running a load test using artillery. When looking at the Phoenix dashboard I see the Ports going to 100% ...
New
aesmail
Hello guys, I have finally made it. I created an admin interface for a framework. It’s been on my todo list for years and with the curre...
New
KronicDeth
Elixir plugin for JetBrain’s IntelliJ Platform (including Rubymine) This is a plugin that adds support for Elixir to JetBrains IntelliJ...
289 36128 110
New
komlanvi
Hi everyone, I was playing with phoenix liveView but I run into an issue. I have a form and want to validate each input text when the te...
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
jononomo
For some reason my phoenix channels are working for me in my local dev environment, but as soon as I deploy via Docker, I get a 403 error...
New

We're in Beta

About us Mission Statement