Welcome! Log In Create A New Profile

Advanced

Re: Nginx cache files by mime type using ngx_srcache module

agentzh
June 11, 2013 03:06PM
Hello!

On Tue, Jun 11, 2013 at 2:10 AM, n1xman wrote:
> Now I need to
> cached them by looking at Content-Type of the header to cache .html pages as
> we do not use the .html extension. (i.e.
> http://www.example.com/this-is-my-site )
>
> Is this possible with ngx_srcache module using map module or something
> similar..
>
> http {
> map $upstream_http_content_type $no_proxy {
> default 0;
> ~*^html/ 0;
> }
>
> and hook this $no_proxy to ngx_srcache variables like I’m doing with
> extension…?
>
> location ~* \.(html)$ {
> set $key $uri$args;

Just a side note: because you're using the key in the "key" URI
argument below, you should escape it because the value may contain
special characters. That is,

set_escape_uri $key $uri$args;

And then in your location = /memc, you should unescape the "key" URI
argument like this:

set_unescape_uri $key $arg_key;

> srcache_fetch GET /memc key=$key;
> srcache_store PUT /memc key=$key&exptime=$ttl_1m;
> proxy_pass http://www.example.com;
> }
>

You can use the srcache_store_skip directive to achieve this:

http://wiki.nginx.org/HttpSRCacheModule#srcache_store_skip

Basically, you can do something like this:

map $upstream_http_content_type $no_store {
default 1;
~*html 0;
}

server {
...
location / {
set_escape_uri $key $uri$args;
srcache_fetch GET /memc key=$key;
srcache_store PUT /memc key=$key&exptime=$ttl_1m;
proxy_pass http://www.example.com;

srcache_store_skip $no_store;
}
}

Best regards,
-agentzh

_______________________________________________
nginx mailing list
nginx@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx
Subject Author Posted

Nginx cache files by mime type using ngx_srcache module

n1xman June 11, 2013 05:10AM

Re: Nginx cache files by mime type using ngx_srcache module

agentzh June 11, 2013 03:06PM

Re: Nginx cache files by mime type using ngx_srcache module

n1xman June 12, 2013 06:51AM

Re: Nginx cache files by mime type using ngx_srcache module

agentzh June 18, 2013 10:24AM

Re: Nginx cache files by mime type using ngx_srcache module

n1xman June 18, 2013 11:37AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 307
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready