# Reverse proxy root folder only

**URL:** <https://www.ruby-forum.com/t/reverse-proxy-root-folder-only/215528>\
**Category:** NGINX\
**Created:** [January 7, 2012, 1:18am UTC](https://www.ruby-forum.com/t/reverse-proxy-root-folder-only/215528 "2012-01-07T01:18:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![luislavena](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/0ea827/32.png) [@luislavena](https://www.ruby-forum.com/u/luislavena)\
**Post date:** [January 7, 2012, 1:18am UTC](https://www.ruby-forum.com/t/reverse-proxy-root-folder-only/215528/1 "2012-01-07T01:18:25Z")

</div>

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:

> **[reverse proxy root folder only](https://forum.nginx.org/read.php?2,220895,220895#msg-220895)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![starmonche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@starmonche](https://www.ruby-forum.com/u/starmonche)\
**Post date:** [January 9, 2012, 6:01pm UTC](https://www.ruby-forum.com/t/reverse-proxy-root-folder-only/215528/2 "2012-01-09T18:01:57Z")

</div>

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](http://myinternalsite.com); }  
location /subfolder { proxy\_pass [http://myinternalsite.com](http://myinternalsite.com); }  
location / { return 444; }

So [http://externalsite.com](http://externalsite.com) and [http://externalsite.com/subfolder](http://externalsite.com/subfolder) both  
work but everything else fails.

Posted at Nginx Forum:

> **[Re: reverse proxy root folder only](https://forum.nginx.org/read.php?2,220895,220969#msg-220969)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![starmonche](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/d2c977/32.png) [@starmonche](https://www.ruby-forum.com/u/starmonche)\
**Post date:** [January 7, 2012, 11:03am UTC](https://www.ruby-forum.com/t/reverse-proxy-root-folder-only/215528/3 "2012-01-07T11:03:11Z")

</div>

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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
