Ivanori

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

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

Qqwy

TypeCheck Core Team

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 :slight_smile: .

minhajuddin

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

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

Where Next?

Popular in Questions Top

New
Emily
I have VueJS GUIs with the project generated using Webpack. I have Elixir modules that will need to be used by the VueJS GUIs. I forese...
New
jay1
Why is it that the mnesia database isn’t the most preferred database for use in Elixir/Phoenix?
New
greenz1
I have a phoenix application from which a user can download multiple(5-6) files of size 1MB. I couldn’t find anything related to sending ...
New
belgoros
I’m not a pro in using Regex and can’t figure out why the following behaviour happens, especially if we take into account the difference ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
Harrisonl
We have an ECS cluster with 4 services, where each task joins a single cluster, via discovery ECS discovery service. Currently when I de...
New

Other popular topics Top

Brian
What is the proper way to load a module from a file in to IEX? In the python world, doing something like this pretty standard: from ....
New
dokuzbir
I want to highlight html closing tags when i click a html tag. That works in .html files but doesnt work for html.eex templates. How can...
New
Darmani72
If I have a post route which an argument: post /my_post_route/:my_param1, MyController.my_post_handler How would get the post params ...
New
bsollish-terakeet
Credo is smart enough to check for (something like) this: assert length(the_list) == 0 with this response: Checking if an enum is empt...
New
shijith.k
I am trying to start a new phoenix project with elixir 1.9, but mix phx.new does not work. It says that ** (Mix) The task "phx.new" could...
New
sergio
Kind of like when jquery came out, it was super necessary. Existing drag and drop libraries have a bunch of baggage to support old browse...
New

We're in Beta

About us Mission Statement