Reverse proxy root folder only

I have an nginx serverset up and I’m looking for a way to only reverse
proxy the contents of the root folder. I’m using a location regex with a
list of the files in root that are allowed and then a second catch-all
location that goes nowhere but there must be an easier or cleaner way to
do this.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,220895,220895#msg-220895

That was exactly what I was looking for, thank you.

I have these locations defined in my server section:

location ~ ^/[^/]*$ { proxy_pass http://myinternalsite.com; }
location /subfolder { proxy_pass http://myinternalsite.com; }
location / { return 444; }

So http://externalsite.com and http://externalsite.com/subfolder both
work but everything else fails.

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,220895,220969#msg-220969

On Fri, Jan 06, 2012 at 07:17:42PM -0500, starmonche wrote:

Hi there,

I have an nginx serverset up and I’m looking for a way to only reverse
proxy the contents of the root folder. I’m using a location regex with a
list of the files in root that are allowed and then a second catch-all
location that goes nowhere but there must be an easier or cleaner way to
do this.

Conceptually, one location{} for the things you want, plus one for all
else, is the easy way to do it.

(That’s more or less the same as one location{} for the things you don’t
want, plus one for all else.)

Arguably the cleaner way is to have one exact location{} for each thing
you want, plus one for the rest, but I guess you’re not looking for
that.

So: what is “the contents of the root folder”? If it is “exactly these
file names”, then your current

location ~ ^/(one|two|three)$

is correct. If it is “any request without a second /”, then

location ~ ^/[^/]*$

should work.

And if you go the other way, and have “location /” as your “this is
the root folder” block, then “all else” would be “any request with two
slashes”, which could be

location ~ /.*/

(All untested, by the way.)

Good luck with it,

f

Francis D. [email protected]

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs