Welcome! Log In Create A New Profile

Advanced

Re: Proxying and static files

Alan Orth
February 21, 2017 10:02AM
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@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@daoine.org
> _______________________________________________
> nginx mailing list
> nginx@nginx.org
> http://mailman.nginx.org/mailman/listinfo/nginx
>
--

Alan Orth
alan.orth@gmail.com
https://englishbulgaria.net
https://alaninkenya.org
https://mjanja.ch
_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Proxying and static files

epoch1 February 16, 2017 08:26AM

Re: Proxying and static files

Francis Daly February 16, 2017 04:40PM

Re: Proxying and static files

Alan Orth February 21, 2017 10:02AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 290
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready