# Location regex issue

**URL:** <https://www.ruby-forum.com/t/location-regex-issue/205776>\
**Category:** NGINX\
**Created:** [April 15, 2011, 11:13am UTC](https://www.ruby-forum.com/t/location-regex-issue/205776 "2011-04-15T11:13:02Z")\
**Posts on this page:** 10\
**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:** [April 15, 2011, 11:13am UTC](https://www.ruby-forum.com/t/location-regex-issue/205776/1 "2011-04-15T11:13:02Z")

</div>

Hi list,

Facing a difficulty here,

I have the following location config:

location ~\* (^/browse/$) {

And this seems to catch URls like /browse/?page=35 and similar.

In my understanding the $ (end of line) symbol should make this location  
work only for /browse/ and nothing more… or am I wrong?

Thanks, Boyko

---

<div class="post-metadata">

**Author:** ![Boyko\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Boyko\_Y](https://www.ruby-forum.com/u/Boyko_Y)\
**Post date:** [April 15, 2011, 11:19am UTC](https://www.ruby-forum.com/t/location-regex-issue/205776/2 "2011-04-15T11:19:13Z")

</div>

On Fri, Apr 15, 2011 at 4:12 PM, Boyko Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> In my understanding the $ (end of line) symbol should make this location work  
> only for /browse/ and nothing more.. or am I wrong?

anything past ? (and ? itself) is argument hence not checked when  
matching location block.

---

<div class="post-metadata">

**Author:** ![Boyko\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Boyko\_Y](https://www.ruby-forum.com/u/Boyko_Y)\
**Post date:** [April 15, 2011, 11:23am UTC](https://www.ruby-forum.com/t/location-regex-issue/205776/3 "2011-04-15T11:23:33Z")

</div>

On Apr 15, 2011, at 12:18 PM, Edho P Arief wrote:

> matching location block.  
> Got u, thanks!

Then how am I supposed to achieve what I’m after? I need to make this  
location work for /browse/ only and not for /browse/?args

Boyko

---

<div class="post-metadata">

**Author:** ![Boyko\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Boyko\_Y](https://www.ruby-forum.com/u/Boyko_Y)\
**Post date:** [April 15, 2011, 11:28am UTC](https://www.ruby-forum.com/t/location-regex-issue/205776/4 "2011-04-15T11:28:29Z")

</div>

On Fri, Apr 15, 2011 at 4:23 PM, Boyko Y. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
wrote:

> > anything past ? (and ? itself) is argument hence not checked when  
> > matching location block.
> 
> Got u, thanks!
> 
> Then how am I supposed to achieve what I’m after? I need to make this location  
> work for /browse/ only and not for /browse/?args

Add a check for $args.

Something like

if ($args == ‘’) { }

(I don’t remember exact syntax. Please check nginx wiki for more detail)

---

<div class="post-metadata">

**Author:** ![Boyko\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Boyko\_Y](https://www.ruby-forum.com/u/Boyko_Y)\
**Post date:** [April 15, 2011, 11:40am UTC](https://www.ruby-forum.com/t/location-regex-issue/205776/5 "2011-04-15T11:40:13Z")

</div>

Hi,

Its:

```
        if ($args = "") {
stuff..
        }

```

Case solved,

Thanks a lot!

Boyko

---

<div class="post-metadata">

**Author:** ![Boyko\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Boyko\_Y](https://www.ruby-forum.com/u/Boyko_Y)\
**Post date:** [April 15, 2011, 12:03pm UTC](https://www.ruby-forum.com/t/location-regex-issue/205776/6 "2011-04-15T12:03:04Z")

</div>

On Fri, Apr 15, 2011 at 12:39:39PM +0300, Boyko Y. wrote:

> Hi,
> 
> Its:
> 
> ```
> if ($args = "") {
> stuff..
> }
> 
> ```

location = /browse/ {  
if ($args != “”) {  
return 404;  
}  
…  
}

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![Boyko\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Boyko\_Y](https://www.ruby-forum.com/u/Boyko_Y)\
**Post date:** [April 15, 2011, 12:19pm UTC](https://www.ruby-forum.com/t/location-regex-issue/205776/7 "2011-04-15T12:19:08Z")

</div>

Thanks Igor,

Actually it was about caching - I needed to cache /browse/ only and not  
/browse/?stuff

I used proxy\_no\_cache $args to make sure cached response wont be used  
when $args are present. Seems to work well, logging only MISSed  
responses, no cache HITs.

Boyko

---

<div class="post-metadata">

**Author:** ![Boyko\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Boyko\_Y](https://www.ruby-forum.com/u/Boyko_Y)\
**Post date:** [April 15, 2011, 1:12pm UTC](https://www.ruby-forum.com/t/location-regex-issue/205776/8 "2011-04-15T13:12:51Z")

</div>

Guys,

Further issue:

I tried to use around 2000 pages in the same location block like this:

location ~\* (^/browse|^/page2|^/page3|… etc ^/page2000) {

And of-course I’m getting:

nginx: [emerg] too long parameter

Can I catch all these pages with a single location directive or I should  
separate them in different locations? Also, what is the allowed size for  
location parameter?

Boyko

---

<div class="post-metadata">

**Author:** ![Boyko\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Boyko\_Y](https://www.ruby-forum.com/u/Boyko_Y)\
**Post date:** [April 15, 2011, 1:23pm UTC](https://www.ruby-forum.com/t/location-regex-issue/205776/9 "2011-04-15T13:23:21Z")

</div>

On Fri, Apr 15, 2011 at 01:18:52PM +0300, Boyko Y. wrote:

> Thanks Igor,
> 
> Actually it was about caching - I needed to cache /browse/ only and not  
> /browse/?stuff
> 
> I used proxy\_no\_cache $args to make sure cached response wont be used when $args  
> are present. Seems to work well, logging only MISSed responses, no cache HITs.

location = /browse/ {  
proxy\_cache\_bypass $args;  
proxy\_no\_cache $args;  
…  
}

–  
Igor S.

---

<div class="post-metadata">

**Author:** ![Boyko\_Y](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/71c47a/32.png) [@Boyko\_Y](https://www.ruby-forum.com/u/Boyko_Y)\
**Post date:** [April 15, 2011, 1:24pm UTC](https://www.ruby-forum.com/t/location-regex-issue/205776/10 "2011-04-15T13:24:35Z")

</div>

On Fri, Apr 15, 2011 at 02:12:26PM +0300, Boyko Y. wrote:

> nginx: [emerg] too long parameter
> 
> Can I catch all these pages with a single location directive or I should  
> separate them in different locations? Also, what is the allowed size for location  
> parameter?

You should not use regex location if you can avoid them.

location = /browse {  
…  
}

location = /page2 {  
…  
}

etc.

–  
Igor S.
