Ivanori
How to tell Phoenix not to handle the assets if I'm using nginx for that?
I want Phoenix to not handle the assets at all in production. How to set it up in such a way?
Most Liked
LostKobrakai
Both. If you don’t send requests of static assets to phoenix in the first place it does not serve them. But if you want to make sure phoenix does not serve any assets no matter what (e.g. nginx being misconfigured) you’d want to disable Plug.Static.
Qqwy
What we usually do is to serve Phoenix behind Nginx (so inside your Nginx configuration you check for the domain name and forward certain calls to phoenix), and make this call conditional depending on if the call corresponds to a path in the priv/static folder.
So we do not tell Phoenix to not handle those (and as a matter of fact, in the development environment it still will) but those requests will simply be handled by Nginx directly and Phoenix will never see them.
I don’t have an example config snippet for you now unfortunately since I am on my phone, but I hope the gist is clear even without it
.
minhajuddin
If you don’t want phoenix to handle those requests just don’t send them to the phoenix server. I usually have an nginx config which looks like below:
server{
server_name awesome.com;
root /opt/www/awesome/path/to/static/assets;
location / {
try_files $uri @proxy;
}
location @proxy{
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
proxy_set_header X_FORWARDED_PROTO $scheme;
proxy_redirect off;
proxy_pass http://localhost:4000;
gzip_proxied any;
}
}
With this nginx will respond if it finds the asset and fallback to cowboy if it doesn’t find the static file.
Last Post!
poops
If you’re using releases, you’ll have to symlink to the release dir, since that will end up changing on every version bump.
Here’s how to do it with edeliver
Popular in Questions
Other popular 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
- #channels
- #elixirconf
- #exunit
- #discussion
- #code-sync
- #javascript
- #podcasts
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #elixir-ls
- #phoenix_html
- #iex
- #blog-post
- #graphql
- #genstage
- #ai
- #websockets
- #supervisor
- #elixirconf-us
- #advent-of-code
- #distillery
- #processes
- #forms
- #api
- #metaprogramming
- #security
- #hex









