sreyansjain

sreyansjain

Run same phoenix app in multiple locations on the same server

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

Most Liked

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

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.

Last Post!

Exadra37

Exadra37

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

Where Next?

Popular in Questions Top

ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
lanycrost
Hi everyone! I need implement if…else if…else condition from my elixir code, and anymore of this control flow structures not work proper...
New
ashish173
I am using Ecto timestamps with postgres, I can see the timestamps() use the :naive_dateime but for my use case I wanted to store the ti...
New
marius95
Hello everyone, I try to use an Javascript Event Handler in my root.html.leex file. Therefore I created a function in the app.js file: ...
New
fayddelight
I tried installing elixir 1.11.2 erlang 23.3.4 via asdf in my zsh shell. Enabled the versions locally and globally. When I list them ...
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
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

Other popular topics Top

minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
jononomo
I am trying to figure out how Mix knows whether the environment is test, dev, or prod – where is this set? Thanks.
New
hariharasudhan94
Lets say I have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
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
SoCreat
i’m a new one to elixir which editor can i use vs code? or atom? Thanks! :smiley:
New

We're in Beta

About us Mission Statement