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.

Where Next?

Popular in Questions Top

vertexbuffer
Hello, can anybody help here..? I have a list of players and I what to delete an element, but every for loop the list is reverting to ori...
New
aadeshere1
I have a another noob question about loop. Since elixir is immutable, while loop is not directly possible. total = 10 while total != 0 ...
New
lessless
I believe there are people here who are dealing with CSV files import on the daily basis, and since Excel is a really popular tool there ...
New
itssasanka
Hi all, Trying to get some more clarity over utc_datetime and naive_datetime for Ecto: https://hexdocs.pm/ecto/Ecto.Schema.html#module-...
New
ycv005
I have followed this StackOverflow post to install the specific version of Erlang. And When I am running mix ecto.setup then getting fol...
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
dblack
I’ve got an issue with an app and I’ve no idea of how to troubleshoot it. I’m hoping someone here might have seen something similar. I p...
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
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
hariharasudhan94
Lets say i have map like this fetching from my database %{"_id" => #BSON.ObjectId<58eb1a7a9ad169198c3dXXXX>, "email" => "XX...
New

Other popular topics Top

siddhant3030
Hi, I have to write a raw query for one of my project. But till now I have used ecto queries and don’t have much experience writing raw ...
New
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
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
nobody
Hi! In PHP: $SERVER['SERVERADDR'] - in Elixir? Searched the docs for ip address and the web, no good results. Thanks!
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
Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
AstonJ
Seen any cool LiveView demos, sample apps or examples? Please post them here! :003:
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