Deploying phoenix with a specific path prepended to all paths

Hi. I need some help deploying my Phoenix app. I currently build the app using Distillery and serve it using Nginx. There are other non-Phoenix apps being served by Nginx already, so I can’t just serve my app at ‘/’
The static assets are packaged with my app and are not served separately with Nginx.

I am trying to serve my app at http://servername/myapp/

I have Nginx setup to reverse proxy the requests to my Phoenix app. The requests reach the Phoenix app. However, the static assets and links (paths to my controllers) don’t work, because they all request it from the / location, which is then not found.

Note that when I start up my app, it show “Running HprsLocalAuthWeb.Endpoint with Cowboy using http://:::4000” with no hostname, no matter what I set it to.

Also, when I perform a request at http://servername/myapp, my Phoenix app outputs the following. The GET // is not right:
15:20:53.989 request_id=2kqp9j2rconlnrrnmk000084 [info] GET //

After serving the app, when I modify the html source tag of the JS or CS file in the browser console and prepend ‘/myapp/’ to it, then it finds the files.

How can I get all the paths in my app to prepend the path ‘/myapp/’ to all requests without hardcoding this in the app itself? Or is there another alternative?

Thanks for any assistance!

What exactly have you tried setting in your endpoint configuration? I believe it should look something like

config :my_app, MyApp.Web.Endpoint,
  http: [port: {:system, "PORT"}],
  url: [host: "servername", path: "/myapp", port: {:system, "PORT"}],
  cache_static_manifest: "priv/static/cache_manifest.json",
  server: true,
  root: ".",
  version: Application.spec(:my_app, :vsn)


Hi Ankhers.

Mine looks almost the same, however, I did not have a path setting at all. After adding that, it works! Thank you so much!
Now it looks like this and serves requests at http://myserver/myapp

config :hprs_local_auth, HprsLocalAuthWeb.Endpoint,
http: [port: "${PORT}"],
load_from_system_env: true,
url: [host: "${HOST}", path: "${APP_PATH}", port: "${PORT}"],
cache_static_manifest: "priv/static/cache_manifest.json",
secret_key_base: "${SECRET_KEY_BASE}",
server: true,
root: "."