Deploy phoenix app to custom base url

Hello everyone, I hope you guys are well.

I am trying to deploy my first phoenix app to a VPS, but I am having some trouble when I usee a path different than the root. i.e.

I am using Caddy as my webserver and I am running phx.server in localhost:4001. So far, I managed to get all the requests that are not static assets to work by stripping the prefix from every request. I am doing something akin to:

route /myapp/* {
    uri strip_prefix /myapp
    reverse_proxy localhost:4001

This works somewhat okay, but then static assets are not requested correctly. When I look into my index.html, I see /css/app-e8309f448e7f2cee3fbce5fba4f81d22.css?vsn=d which is incorrect, as /myapp should be prepended to it.

I went and looked into root.html.leex, and these assets are imported as follows:

Routes.static_path(@conn, "/css/app.css")

So my question is: How can I configure phoenix to deploy an app at a custom path which is not the root of a site?

I tinkered with the url in config.exs and prod.exs, but to no avail.

Thank you very much for the help, and please let me know if you need additional information.

Update: As pointed out by LostKobrakai, I needed to use the :url options properly. As I was using LiveView as well, I had to update my app.js to reflect the new path.

That’s actually the solution, which should work: url: [path: "/myapp", …]. Can’t say why it didn’t work for you.

1 Like

I had not read the format of url: in detail. Thank you for your help

1 Like