sreyansjain

sreyansjain

Hi,

I have one phoenix app that I need to run in multiple locations on the same server.
For ex lets say the server is app.example.com
I want to run it on app.example.com/instance1, app.example.com/instance2 and so on.
I have an nginx server in front of the phoenix app and have nginx blocks like so -
location /instance1 {
proxy_http_version 1.1;
proxy_pass https://app.example.com:4013;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto https;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection “Upgrade”;
proxy_redirect off;
}
Similar for instance2, 3 etc.

For the phoenix app I need to have all routes begin with /instance1 and all static assets served from /instance1
This works well when I have only one instance. If i build a release using mix release and want to copy the instances, it doesn’t work.
I am trying to put something like below in the config/releases.exs file and use the same in routes

config :app_name,
  app_prefix: "/instance1"

for routes

scope "#{Application.get_env(:app_name, :app_prefix)}/admin/", AppNameWeb do

But it seams that the routes are only generated at compile time and not at runtime.
Is there a possibility of generating the routes at runtime using a config setting?

Sorry for the long post, but did not understand how else to put it.
Help would be deeply appreciated.

Thanks

Showing Posts 1 to 6

NobbZ

NobbZ

You probably want to configure your endpoint correctly using the :url option of the endpoint configuration:

:url - configuration for generating URLs throughout the app. Accepts the :host , :scheme , :path and :port options. All keys except :path can be changed at runtime. Defaults to:

[host: "localhost", path: "/"]

The :port option requires either an integer, string, or {:system, "ENV_VAR"} . When given a tuple like {:system, "PORT"} , the port will be referenced from System.get_env("PORT") at runtime as a workaround for releases where environment specific information is loaded only at compile-time.

The :host option requires a string or {:system, "ENV_VAR"} . Similar to :port , when given a tuple like {:system, "HOST"} , the host will be referenced from System.get_env("HOST") at runtime.

The :scheme option accepts "http" and "https" values. Default value is infered from top level :http or :https option. It is useful when hosting Phoenix behind a load balancer or reverse proxy and terminating SSL there.

The :path option can be used to override root path. Useful when hosting Phoenix behind a reverse proxy with URL rewrite rules

sreyansjain

sreyansjain OP

I am trying permutations and combinations with the url.
I am able to change the port no etc at runtime so if I copy over a release I am able to get multiple running apps on different ports.

The problem comes during configuration with nginx proxy. I think to work in a subfolder phoenix routes need to being with the subfolder and all static assets need to be served from the subfolder also.

At the moment I can get that to work by creating multiple releases with different subfolders, but I want to automate this process so that I don’t need to create multiple releases. Just copying the release and changing the runtime config to get the app rolling.

Will post the updates here.
Thanks for the help.

NobbZ

NobbZ

Well, :path is explicitely named as not beeing runtime configurable.

Also you can not change routes via a runtime parameter, as they need to be compiled into literal binary pattern matches.

Currently I do see no possibility to do what you want.

sreyansjain

sreyansjain OP

Seems like compiling multiple times is the only way forward for now. Thank you for your time and help.

Exadra37

Exadra37

Would Multiple Endpoints in Phoenix help you to achieve what you want?

Take also a look into this thread What is benefit of having multiple phoenix endpoints.

Exadra37

Exadra37

Seems the link is dead, but waybackmachine as a copy of it:

— All posts loaded —

Where Next? Top

Trending in Questions Top

Blokh
Hey guys, I’ve got a huge CSV ( around 10 GB ) that needs to be processed hourly Do you guys have any suggestions what is the best prac...
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
matt-savvy
Anyone here using Honeybadger? My Honeybadger account is being overwhelmed with noise from some bots. Seeing a lot of Bandit.HTTPError...
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

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
garrison
Hobbes is a low-level distributed database for the Elixir programming language. Hobbes provides a simple, safe, and scalable storage lay...
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
mcass19
ExRatatui lets you cook up rich terminal UIs in Elixir, powered by Rust’s ratatui via Rustler NIFs. Build interactive terminal applicatio...
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
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