Proxying and static files

Alan Orth alan.orth at gmail.com
Tue Feb 21 15:01:12 UTC 2017


Hi,

The try_files directive is great for this[0]. But like Francis pointed out,
you need to have a pattern that can be matched for static files, and then
nginx can look for the files on disk (relative to the root) before proxying
the request back to the dynamic application.

Regards,

[0] http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files

On Thu, Feb 16, 2017 at 11:38 PM Francis Daly <francis at daoine.org> wrote:

> On Thu, Feb 16, 2017 at 08:26:35AM -0500, epoch1 wrote:
>
> Hi there,
>
> > I've tried something like the following but can't get it work for each
> app:
> > location ~* /(images|css|js|files)/ {
> >     root /home/username/app1/public/;
> > }
> >
> > If I request app1/js/script.js for example it goes to
> > /home/username/app1/public/app1/js/script.js rather than
> > /home/username/app1/public/js/script.js
>
> If the web request /one/two/thr.ee does not correspond to a file
> /docroot/one/two/thr.ee, then you probably want to use "alias"
> (http://nginx.org/r/alias) instead of "root".
>
> It's not clear to me what your exact pattern for recognising "static"
> vs "dynamic" files is; perhaps something like one of
>
>   location /app1/images/ {
>     alias /home/username/app1/public/images/;
>   }
>
> (with similar things for the other directories); or
>
>   location ~* ^/app1/(images|css|js|files)/(.*) {
>     alias /home/username/app1/public/$1/$2;
>   }
>
> or
>
>   location ~* ^/app1/(.*.(js|css))$ {
>     alias /home/username/app1/public/$1;
>   }
>
> In each case, the "location"s (particularly the regex one) could be
> nested within the matching "main" location that you already have.
>
> God luck with it,
>
>         f
> --
> Francis Daly        francis at daoine.org
> _______________________________________________
> nginx mailing list
> nginx at nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
-- 

Alan Orth
alan.orth at gmail.com
https://englishbulgaria.net
https://alaninkenya.org
https://mjanja.ch
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.nginx.org/pipermail/nginx/attachments/20170221/c339abfb/attachment.html>


More information about the nginx mailing list