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

Francis Daly francis at daoine.org
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 http://www.site.com
> 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
http://127.0.0.1:8081/two.txt and return whatever it returns.

A similar thing happens for every other request.

http://127.0.0.1:8081/ is a separate web server which is running "real"
Laravel.

So, for the following requests, nginx should:

> http://www.site.com/app1/

proxy to http://127.0.0.1:8081/

> http://www.site.com/app1/index.php 

proxy to http://127.0.0.1:8081/index.php

> http://www.site.com/app1/api/method (pretty urls)

proxy to http://127.0.0.1:8081/api/method

> http://www.site.com/app1/css/bootstram.min.css  (static files)

proxy to http://127.0.0.1:8081/css/bootstram.min.css


> 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 http://127.0.0.1:8081;
> 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/;
    proxy_pass http://127.0.0.1:8081/;
    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.)

	f
-- 
Francis Daly        francis at daoine.org



More information about the nginx mailing list