<div dir="ltr">Hi,<div><br></div><div>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.</div><div><br></div><div>Regards,</div><div><br></div><div>[0] <a href="http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files">http://nginx.org/en/docs/http/ngx_http_core_module.html#try_files</a></div></div><br><div class="gmail_quote"><div dir="ltr">On Thu, Feb 16, 2017 at 11:38 PM Francis Daly <<a href="mailto:francis@daoine.org">francis@daoine.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Thu, Feb 16, 2017 at 08:26:35AM -0500, epoch1 wrote:<br class="gmail_msg">
<br class="gmail_msg">
Hi there,<br class="gmail_msg">
<br class="gmail_msg">
> I've tried something like the following but can't get it work for each app:<br class="gmail_msg">
> location ~* /(images|css|js|files)/ {<br class="gmail_msg">
> root /home/username/app1/public/;<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> If I request app1/js/script.js for example it goes to<br class="gmail_msg">
> /home/username/app1/public/app1/js/script.js rather than<br class="gmail_msg">
> /home/username/app1/public/js/script.js<br class="gmail_msg">
<br class="gmail_msg">
If the web request /one/two/<a href="http://thr.ee" rel="noreferrer" class="gmail_msg" target="_blank">thr.ee</a> does not correspond to a file<br class="gmail_msg">
/docroot/one/two/<a href="http://thr.ee" rel="noreferrer" class="gmail_msg" target="_blank">thr.ee</a>, then you probably want to use "alias"<br class="gmail_msg">
(<a href="http://nginx.org/r/alias" rel="noreferrer" class="gmail_msg" target="_blank">http://nginx.org/r/alias</a>) instead of "root".<br class="gmail_msg">
<br class="gmail_msg">
It's not clear to me what your exact pattern for recognising "static"<br class="gmail_msg">
vs "dynamic" files is; perhaps something like one of<br class="gmail_msg">
<br class="gmail_msg">
location /app1/images/ {<br class="gmail_msg">
alias /home/username/app1/public/images/;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
(with similar things for the other directories); or<br class="gmail_msg">
<br class="gmail_msg">
location ~* ^/app1/(images|css|js|files)/(.*) {<br class="gmail_msg">
alias /home/username/app1/public/$1/$2;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
or<br class="gmail_msg">
<br class="gmail_msg">
location ~* ^/app1/(.*.(js|css))$ {<br class="gmail_msg">
alias /home/username/app1/public/$1;<br class="gmail_msg">
}<br class="gmail_msg">
<br class="gmail_msg">
In each case, the "location"s (particularly the regex one) could be<br class="gmail_msg">
nested within the matching "main" location that you already have.<br class="gmail_msg">
<br class="gmail_msg">
God luck with it,<br class="gmail_msg">
<br class="gmail_msg">
f<br class="gmail_msg">
--<br class="gmail_msg">
Francis Daly <a href="mailto:francis@daoine.org" class="gmail_msg" target="_blank">francis@daoine.org</a><br class="gmail_msg">
_______________________________________________<br class="gmail_msg">
nginx mailing list<br class="gmail_msg">
<a href="mailto:nginx@nginx.org" class="gmail_msg" target="_blank">nginx@nginx.org</a><br class="gmail_msg">
<a href="http://mailman.nginx.org/mailman/listinfo/nginx" rel="noreferrer" class="gmail_msg" target="_blank">http://mailman.nginx.org/mailman/listinfo/nginx</a><br class="gmail_msg">
</blockquote></div><div dir="ltr">-- <br></div><div data-smartmail="gmail_signature"><div dir="ltr"><p dir="ltr">Alan Orth<br>
<a href="mailto:alan.orth@gmail.com">alan.orth@gmail.com</a><br>
<a href="https://englishbulgaria.net">https://englishbulgaria.net</a><br>
<a href="https://alaninkenya.org">https://alaninkenya.org</a><br>
<a href="https://mjanja.ch">https://mjanja.ch</a></p>
</div></div>