A Challenging Config

Ok, Ive been working on a project for a long time. It involves automated
config file building for the nginx web server :slight_smile:
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

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?

http://nginx.org/r/proxy_ignore_headers

 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:

http://nginx.org/r/location

Maxim D.

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)?

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 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.