peppy

peppy

Starting with a fresh install of Phoenix on a Ubuntu 20.04 server with Apache2, what are the specific steps for setting up a reverse proxy (what should the block of code in apache be exactly? what do I edit in the phoenix app files?)

By default, Phoenix runs fine on: https://www.mysite.com:4000/

I want it to run on: https://www.mysite.com/ex/ (without the port 4000 in the URL)

The “Welcome To Phoenix” page and all css/js/image files should load, the live view frame should load and the sockets should work with no errors.

Right now, I have something like the following in my Apache config:

<VirtualHost *:443>
ServerName www.mysite.com
ServerAlias mysite.com
 <Location /ex/>
    ProxyPass http://127.0.0.1:4000/
    ProxyPassReverse http://127.0.0.1:4000/
  </Location>
</VirtualHost>

In Phoenix, I edited config/config.exs to something like this:

config :exchat, ExchatWeb.Endpoint,
  url: [host: "localhost", path: "/ex"],

At the moment, the phoenix page on the website (css/js/images) loads up fine, but the sockets aren’t working. In the console, I’m seeing repeating errors like:

WebSocket connection to 'wss://www.mysite.com/socket/websocket?token=undefined&vsn=2.0.0' failed
WebSocket connection to 'wss://www.mysite.com/ex/phoenix/live_reload/socket/websocket?vsn=2.0.0' failed

Thanks

Showing Posts 1 to 4

derek-zhou

derek-zhou

Running an application involve phoenix sockets not at the root path is tricky. Do you really want to do that? In the old time, people do this to save a separate https cert. now that letsencrypt is free, most people will just make another sub domain and build a virtual host.

If you really want to do this, check your app.js for the socket connection statement. You may want to fix that to your path prefix.

peppy

peppy OP

Thanks for the suggestion, it didn’t cross my mind to use a sub-domain. Based on my reading, I just assumed using Phoenix on a domain directory path was standard practice.

Aetherus

Aetherus

Using separate subdomains has some extra benefits:

  • Cookies are managed separately by default. There’s no need to specify the path option in cookies.
  • CORS strategies can be configured separately so that your applications are more secure than sharing the same domain.
  • Your URLs are shorter and easier to remember.
derek-zhou

derek-zhou

Depends on how do you define standard. If you do not use socket, then it is just as simple as adding a path to endpoint config. If you use socket, the js part need to be modified accordingly. I pass the application root through a data attributes of the the body tag, and connect the lv socket using that. This way the socket path is “float” wrt to the location:

https://github.com/derek-zhou/liv/blob/daf91cccc953f0096d5cbee5f847d4ece8d6f4f3/assets/js/app.js#L173

— All posts loaded —

Where Next? Top

Trending in Questions Top

RSP87
I’m working on a project that simulates the bumbl example in the programming phoenix book. It acts almost like an email client. We have a...
New
kszambelanczyk
Hello! Could someone please give me a help/sample code, how to delete a file from s3 using waffle/waffle_ecto from Phoenix app. I creat...
New
RemyXRenard
I’m seeing that a list inside a Kino.DataTable will be interpreted as a charlist, even if the Kino.configure() is set to charlists: :as_l...
New
velrest
So my question is quite simple and i have found no conclusive answer on forum, google or AI. Should we use :erlang.float for Integer to ...
New
samoloth
Hi, I’ve just set up an application with ash_authentication. There is only magic link strategy for now, so there is no confirmation add o...
New
FlyingNoodle
If a change or preparation module uses Ash.Changeset.get_argument/2 or Ash.Query.get_argument/2 (or any of the other get_argument functio...
New
ryanwinchester
apply_graft/2 doesn’t rewrite an add_many sub-workflow’s deps on an add step. Grafted jobs cancel with “upstream job was deleted” Version...
New

Other Trending Topics Top

mudasobwa
I am happy to introduce the very α version of the new programming language compiled to BEAM. Welcome Cure. It has literally three kille...
New
marciok
Hi there! We created Gust: A task orchestrator inspired by Airflow. For those who have never heard about Aiflow, it’s a Python-based wor...
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
Dmk
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Damirados
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge &amp; Solve. They are GUI (Emerge) and State management (S...
New
netoum
Corex is an accessible, unstyled UI component library for Phoenix that integrates Zag.js state machines using Vanilla JavaScript and Live...
New

We're in Beta

About us Mission Statement

Options

Thread Display Mode




Thread Preview

Skip Thread Previews