# A Challenging Config

**URL:** <https://www.ruby-forum.com/t/a-challenging-config/220924>\
**Category:** NGINX\
**Created:** [June 25, 2012, 4:31pm UTC](https://www.ruby-forum.com/t/a-challenging-config/220924 "2012-06-25T16:31:07Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![aris](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/258eb7/32.png) [@aris](https://www.ruby-forum.com/u/aris)\
**Post date:** [June 25, 2012, 4:31pm UTC](https://www.ruby-forum.com/t/a-challenging-config/220924/1 "2012-06-25T16:31:07Z")

</div>

Ok, Ive been working on a project for a long time. It involves automated  
config file building for the nginx web server 🙂  
Now im adding caching. The user of the software can using the interface  
select regex’s to apply caching logic to.

Ive devided the cache types into 3 types:

1. CACHE: Cache if possible
2. FORCE-CACHE: Cache always, ignore Cache-Control headers
3. NEVER CACHE

all other traffic is caught by the default “/” location. Execution order  
for these statements is from 1-\>3 (e.g 3 should override 1).

I have a couple questions:

1. How can I ignore the effect of cache control on caching?  
proxy\_hide\_header?

2. What is the most efficient order to acheive this caching override  
system, my origional idea was to just use location blocks like

location ~ to\_cache {  
proxy\_cache …;  
proxy\_pass …;  
}

location ~ not\_to\_cache {  
proxy\_cache off;  
proxy\_pass …;  
}

location / {  
proxy\_pass …;  
}

is this right? Im not really sure I understand the wiki text on matching  
order.

Thanks in advance,  
SplitIce

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 25, 2012, 5:03pm UTC](https://www.ruby-forum.com/t/a-challenging-config/220924/2 "2012-06-25T17:03:18Z")

</div>

Hello!

On Tue, Jun 26, 2012 at 12:30:13AM +1000, SplitIce wrote:

> all other traffic is caught by the default “/” location. Execution order  
> for these statements is from 1-\>3 (e.g 3 should override 1).
> 
> I have a couple questions:
> 
> 1. How can I ignore the effect of cache control on caching?  
> proxy\_hide\_header?

> **[Module ngx\_http\_proxy\_module](http://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_ignore_headers)**
>
> The ngx\_http\_proxy\_module module allows passing requests to another server.

> ```
> proxy_pass ....;
> 
> ```
> 
> }
> 
> location / {  
> proxy\_pass …;  
> }
> 
> is this right? Im not really sure I understand the wiki text on matching  
> order.

Try official docs instead, it might be better:

> **[Module ngx\_http\_core\_module](http://nginx.org/en/docs/http/ngx_http_core_module.html#location)**
>
> This directive appeared in version 1.11.8.

Maxim D.

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 26, 2012, 5:36am UTC](https://www.ruby-forum.com/t/a-challenging-config/220924/3 "2012-06-26T05:36:42Z")

</div>

Ok thanks, my problem isnt with the matching order (bad explination on  
my  
part) but more with the matching procedure

e.g

location ~ to\_cache {  
proxy\_cache …;  
proxy\_pass …;  
}

location ~ not\_to\_cache {  
proxy\_cache off;  
proxy\_pass …;  
}

/  
If the url /abc-not\_to\_cache-def/ is passed to nginx does the server  
execute both the matches (to\_cache, then not\_to\_cache with not\_to\_cache  
overriding to\_cache) or does it stop after the first match (to\_cache)?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [June 26, 2012, 8:44am UTC](https://www.ruby-forum.com/t/a-challenging-config/220924/4 "2012-06-26T08:44:49Z")

</div>

Hello!

On Tue, Jun 26, 2012 at 01:35:59PM +1000, SplitIce wrote:

> location ~ not\_to\_cache {  
> proxy\_cache off;  
> proxy\_pass …;  
> }
> 
> /  
> If the url /abc-not\_to\_cache-def/ is passed to nginx does the server  
> execute both the matches (to\_cache, then not\_to\_cache with not\_to\_cache  
> overriding to\_cache) or does it stop after the first match (to\_cache)?

Quoting from [Module ngx\_http\_core\_module](http://nginx.org/r/location), the link already suggested:

: Then regular expressions are checked, in the order of their  
: appearance in a configuration file. A search of regular  
: expressions terminates on the first match, and the corresponding  
: configuration is used.

[…]

Maxim D.
