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
Trending in Questions
Other Trending Topics
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #deployment
- #library
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixir-ls
- #elixirconf-us
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming










Showing Posts 1 to 6- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
NobbZ
You probably want to configure your endpoint correctly using the
:urloption of the endpoint configuration:sreyansjain
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
Well,
:pathis 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
Seems like compiling multiple times is the only way forward for now. Thank you for your time and help.
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
Seems the link is dead, but waybackmachine as a copy of it: