nested location, proxy, alias and multiple "/" locations

Francis Daly francis at
Sun Jan 19 11:02:33 UTC 2014

On Sun, Jan 19, 2014 at 04:57:27AM -0500, sergiks wrote:

Hi there,

I'll describe what I think you want you want nginx to do. Please correct
me where I've guessed wrongly.

> There's a web root  /var/www/site/ that responds to
> Then there's a Laravel (front controller php framework) installation in
> /var/www/Laravel1, and its web root folder is in /var/www/Laravel1/public/ 
> (index.php and static files are there)

> I want to let that Laravel app to respond to URIs under /app1/:

A request for /app1/one.png should return the file
/var/www/Laravel1/public/one.png or respond 404.

A similar mapping applies for every request that end in .png, .jpg,
and .gif, case-insensitively.

A request for /app1/two.txt should proxy_pass to and return whatever it returns.

A similar thing happens for every other request. is a separate web server which is running "real"

So, for the following requests, nginx should:


proxy to


proxy to

> (pretty urls)

proxy to

>  (static files)

proxy to

> The docs only says about a simple "location /i/" case
> and a regexp case. 

"^~" is a prefix location. The "non-regex" documentation applies.

> My q is "location ^~ /i/" which seems to skip the replacement as in the
> simple case:
> location ^~ /app1/ {
> alias /var/www/Laravel/public/;
> proxy_pass;
> This example passes unchanged "/app1/api/method" to the proxy, instead of
> "/api/method"

That's clear, thanks.

That is working as intended. Your expectation is wrong.

"alias" (along with "root") does not affect "proxy_pass".

Does the following do what you want?

  location ^~ /app1/ {
    alias /var/www/Laravel1/public/;
    location ~* \.(jpg|gif|png)$ {}

(In general, unless the proxied server is careful, there are likely to
be problems trying to change parts of the url as is done above.)

Francis Daly        francis at

More information about the nginx mailing list