When assets are served by Phoenix, I can resolve their paths by “static_path(@conn, “/images/something.jpg”)”
What if I switch to nginx and make it serve those assets? They’ll be placed in a folder external to my Phoenix app.
How then will I be able to resolve their paths from my app using “static_path(@conn, “/images/something.jpg”)” function?
How do you deploy? AFAIK even releases have a priv/static folder in them. Personally I don’t use releases yet, I just compile (code and frontend assets) on the target system and then mix phx.digest. My priv/static folder doesn’t disappear anywhere.
I usually have a symlink called current pointing to the latest release, which is updated as part of the deploy process. This way you can configure your nginx to use the symlink to traverse to the priv folder.
It also seems possible to reconfigure where Plug.Static looks for content:
diff --git a/lib/hello_static_web/endpoint.ex b/lib/hello_static_web/endpoint.ex
index 2b13357..f034319 100644
--- a/lib/hello_static_web/endpoint.ex
+++ b/lib/hello_static_web/endpoint.ex
@@ -8,7 +8,7 @@ defmodule HelloStaticWeb.Endpoint do
# You should set gzip to true if you are running phoenix.digest
# when deploying your static files in production.
plug Plug.Static,
- at: "/", from: :hello_static, gzip: false,
+ at: "/", from: "/tmp/hello_static", gzip: false,
only: ~w(css fonts images js favicon.ico robots.txt)
# Code reloading can be explicitly enabled under the
However, you’ll still need to deploy any changes to static assets to the required location of course… In my simple test case, it was just:
cp -rp priv/static /tmp/hello_static
But it’ll naturally be more involved for a proper deployment process. You get that “for free” if you rely on the priv/static directory inside the release, at the cost (as you noticed) of configuring eg. NGINX properly. I’m also not sure at what scale you’ll really benefit from having NGINX serve the content, as opposed to Phoenix.