Git Product home page Git Product logo

srcache-nginx-module's Introduction

Name

ngx_srcache - Transparent subrequest-based caching layout for arbitrary nginx locations

This module is not distributed with the Nginx source. See the installation instructions.

Table of Contents

Status

This module is production ready.

Version

This document describes srcache-nginx-module v0.32 released on 2 July 2020.

Synopsis

 upstream my_memcached {
     server 10.62.136.7:11211;
     keepalive 10;
 }

 location = /memc {
     internal;

     memc_connect_timeout 100ms;
     memc_send_timeout 100ms;
     memc_read_timeout 100ms;
     memc_ignore_client_abort on;

     set $memc_key $query_string;
     set $memc_exptime 300;

     memc_pass my_memcached;
 }

 location /foo {
     set $key $uri$args;
     srcache_fetch GET /memc $key;
     srcache_store PUT /memc $key;
     srcache_store_statuses 200 301 302 307 308;

     # proxy_pass/fastcgi_pass/drizzle_pass/echo/etc...
     # or even static files on the disk
 }
 location = /memc2 {
     internal;

     memc_connect_timeout 100ms;
     memc_send_timeout 100ms;
     memc_read_timeout 100ms;
     memc_ignore_client_abort on;

     set_unescape_uri $memc_key $arg_key;
     set $memc_exptime $arg_exptime;

     memc_pass unix:/tmp/memcached.sock;
 }

 location /bar {
     set_escape_uri $key $uri$args;
     srcache_fetch GET /memc2 key=$key;
     srcache_store PUT /memc2 key=$key&exptime=$srcache_expire;

     # proxy_pass/fastcgi_pass/drizzle_pass/echo/etc...
     # or even static files on the disk
 }
 map $request_method $skip_fetch {
     default     0;
     POST        1;
     PUT         1;
 }

 server {
     listen 8080;

     location /api/ {
         set $key "$uri?$args";

         srcache_fetch GET /memc $key;
         srcache_store PUT /memc $key;

         srcache_methods GET PUT POST;
         srcache_fetch_skip $skip_fetch;

         # proxy_pass/drizzle_pass/content_by_lua/echo/...
     }
 }

Back to TOC

Description

This module provides a transparent caching layer for arbitrary nginx locations (like those use an upstream or even serve static disk files). The caching behavior is mostly compatible with RFC 2616.

Usually, memc-nginx-module is used together with this module to provide a concrete caching storage backend. But technically, any modules that provide a REST interface can be used as the fetching and storage subrequests used by this module.

For main requests, the srcache_fetch directive works at the end of the access phase, so the standard access module's allow and deny direcives run before ours, which is usually the desired behavior for security reasons.

The workflow of this module looks like below:

srcache flowchart

Back to TOC

Subrequest caching

For subrequests, we explicitly disallow the use of this module because it's too difficult to get right. There used to be an implementation but it was buggy and I finally gave up fixing it and abandoned it.

However, if you're using lua-nginx-module, it's easy to do subrequest caching in Lua all by yourself. That is, first issue a subrequest to an memc-nginx-module location to do an explicit cache lookup, if cache hit, just use the cached data returned; otherwise, fall back to the true backend, and finally do a cache insertion to feed the data into the cache.

Using this module for main request caching and Lua for subrequest caching is the approach that we're taking in our business. This hybrid solution works great in production.

Back to TOC

Distributed Memcached Caching

Here is a simple example demonstrating a distributed memcached caching mechanism built atop this module. Suppose we do have three different memcached nodes and we use simple modulo to hash our keys.

 http {
     upstream moon {
         server 10.62.136.54:11211;
         server unix:/tmp/memcached.sock backup;
     }

     upstream earth {
         server 10.62.136.55:11211;
     }

     upstream sun {
         server 10.62.136.56:11211;
     }

     upstream_list universe moon earth sun;

     server {
         memc_connect_timeout 100ms;
         memc_send_timeout 100ms;
         memc_read_timeout 100ms;

         location = /memc {
             internal;

             set $memc_key $query_string;
             set_hashed_upstream $backend universe $memc_key;
             set $memc_exptime 3600; # in seconds
             memc_pass $backend;
         }

         location / {
             set $key $uri;
             srcache_fetch GET /memc $key;
             srcache_store PUT /memc $key;

             # proxy_pass/fastcgi_pass/content_by_lua/drizzle_pass/...
         }
     }
 }

Here's what is going on in the sample above:

  1. We first define three upstreams, moon, earth, and sun. These are our three memcached servers.
  2. And then we group them together as an upstream list entity named universe with the upstream_list directive provided by set-misc-nginx-module.
  3. After that, we define an internal location named /memc for talking to the memcached cluster.
  4. In this /memc location, we first set the $memc_key variable with the query string ($args), and then use the set_hashed_upstream directive to hash our $memc_key over the upsteam list universe, so as to obtain a concrete upstream name to be assigned to the variable $backend.
  5. We pass this $backend variable into the memc_pass directive. The $backend variable can hold a value among moon, earth, and sun.
  6. Also, we define the memcached caching expiration time to be 3600 seconds (i.e., an hour) by overriding the $memc_exptime variable.
  7. In our main public location /, we configure the $uri variable as our cache key, and then configure srcache_fetch for cache lookups and srcache_store for cache updates. We're using two subrequests to our /memc location defined earlier in these two directives.

One can use lua-nginx-module's set_by_lua or rewrite_by_lua directives to inject custom Lua code to compute the $backend and/or $key variables in the sample above.

One thing that should be taken care of is that memcached does have restriction on key lengths, i.e., 250 bytes, so for keys that may be very long, one could use the set_md5 directive or its friends to pre-hash the key to a fixed-length digest before assigning it to $memc_key in the /memc location or the like.

Further, one can utilize the srcache_fetch_skip and srcache_store_skip directives to control what to cache and what not on a per-request basis, and Lua can also be used here in a similar way. So the possibility is really unlimited.

To maximize speed, we often enable TCP (or Unix Domain Socket) connection pool for our memcached upstreams provided by HttpUpstreamKeepaliveModule, for example,

 upstream moon {
     server 10.62.136.54:11211;
     server unix:/tmp/memcached.sock backup;
     keepalive 10;
 }

where we define a connection pool which holds up to 10 keep-alive connections (per nginx worker process) for our moon upstream (cluster).

Back to TOC

Caching with Redis

Redis is an alternative key-value store with many additional features.

Here is a working example using the lua-resty-redis module:

  location ~ '\.php$|^/update.php' {
    # cache setup
    set $key $request_uri;
    try_files $uri =404;

    srcache_fetch_skip $skip_cache;
    srcache_store_skip $skip_cache;

    srcache_response_cache_control off;
    srcache_store_statuses 200 201 301 302 307 308 404 503;

    set_escape_uri $escaped_key $key;

    srcache_fetch GET /redis-fetch $key;
    srcache_store PUT /redis-store key=$escaped_key;

    more_set_headers 'X-Cache-Fetch-Status $srcache_fetch_status';
    more_set_headers 'X-Cache-Store-Status $srcache_store_status';

    fastcgi_split_path_info ^(.+?\.php)(|/.*)$;
    # Security note: If you're running a version of PHP older than the
    # latest 5.3, you should have "cgi.fix_pathinfo = 0;" in php.ini.
    # See http://serverfault.com/q/627903/94922 for details.
    include fastcgi_params;
    # Block httproxy attacks. See https://httpoxy.org/.
    fastcgi_param HTTP_PROXY "";
    fastcgi_param SCRIPT_FILENAME /var/www/html/$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    fastcgi_param QUERY_STRING $query_string;
    fastcgi_intercept_errors on;

    fastcgi_pass upstream-name;
  }

  location /redis-fetch {
    internal;

    resolver 8.8.8.8 valid=300s;
    resolver_timeout 10s;

    content_by_lua_block {
      local key = assert(ngx.var.request_uri, "no key found")
      local redis = require "resty.redis"
      local red, err = redis:new()
      if not red then
        ngx.log(ngx.ERR, "Failed to create redis variable, error -> ", err)
        ngx.exit(500)
      end
      assert(red:connect("redis-master.default.svc.cluster.local", 6379))
      if not red then
        ngx.log(ngx.ERR, "Failed to connect to redis, error -> ", err)
        ngx.exit(500)
      end
      local res, err = red:auth("redispassword")
      if not res then
        ngx.say("failed to authenticate, ", err)
        ngx.exit(500)
      end
      local data = assert(red:get(key))
      assert(red:set_keepalive(10000, 100))
      if res == ngx.null then
        return ngx.exit(404)
      end
      ngx.print(data)
    }
  }

  location /redis-store {
    internal;

    resolver 8.8.8.8 valid=300s;
    resolver_timeout 10s;

    content_by_lua_block {
      local value = assert(ngx.req.get_body_data(), "no value found")
      local key = assert(ngx.var.request_uri, "no key found")
      local redis = require "resty.redis"
      local red, err = redis:new()
      if not red then
        ngx.log(ngx.ERR, "Failed to create redis variable, error -> ", err)
        ngx.exit(500)
      end
      assert(red:connect("redis-master.default.svc.cluster.local", 6379))
      if not red then
        ngx.log(ngx.ERR, "Failed to connect to redis, error -> ", err)
        ngx.exit(500)
      end
      local res, err = red:auth("redispassword")
      if not res then
        ngx.say("failed to authenticate, ", err)
        ngx.exit(500)
      end
      local data = assert(red:set(key, value))
      assert(red:set_keepalive(10000, 100))
      if res == ngx.null then
        return ngx.exit(404)
      end
    }
  }

Here is a working example by using the HTTPRedis (fetch) and Redis2 (store) modules:

 location /api {
     default_type text/css;

     set $key $uri;
     set_escape_uri $escaped_key $key;

     srcache_fetch GET /redis $key;
     srcache_store PUT /redis2 key=$escaped_key&exptime=120;

     # fastcgi_pass/proxy_pass/drizzle_pass/postgres_pass/echo/etc
 }

 location = /redis {
     internal;

     set_md5 $redis_key $args;
     redis_pass 127.0.0.1:6379;
 }

 location = /redis2 {
     internal;

     set_unescape_uri $exptime $arg_exptime;
     set_unescape_uri $key $arg_key;
     set_md5 $key;

     redis2_query set $key $echo_request_body;
     redis2_query expire $key $exptime;
     redis2_pass 127.0.0.1:6379;
 }

This example makes use of the $echo_request_body variable provided by echo-nginx-module. Note that you need the latest version of echo-nginx-module, v0.38rc2 because earlier versions may not work reliably.

Also, you need both HttpRedisModule and redis2-nginx-module. The former is used in the srcache_fetch subrequest and the latter is used in the srcache_store subrequest.

The Nginx core also has a bug that could prevent redis2-nginx-module's pipelining support from working properly in certain extreme conditions. And the following patch fixes this:

http://mailman.nginx.org/pipermail/nginx-devel/2012-March/002040.html

Note that, however, if you are using the OpenResty 1.0.15.3 bundle or later, then you already have everything that you need here in the bundle.

Back to TOC

Cache Key Preprocessing

It is often desired to preprocess the cache key to exclude random noises that may hurt the cache hit rate. For example, random session IDs in the URI arguments are usually desired to get removed.

Consider the following URI querystring

SID=BC3781C3-2E02-4A11-89CF-34E5CFE8B0EF&UID=44332&L=EN&M=1&H=1&UNC=0&SRC=LK&RT=62

we want to remove the SID and UID arguments from it. It is easy to achieve if you use lua-nginx-module at the same time:

 location = /t {
     rewrite_by_lua '
         local args = ngx.req.get_uri_args()
         args.SID = nil
         args.UID = nil
         ngx.req.set_uri_args(args)
     ';

     echo $args;
 }

Here we use the echo directive from echo-nginx-module to dump out the final value of $args in the end. You can replace it with your srcache-nginx-module configurations and upstream configurations instead for your case. Let's test this /t interface with curl:

$ curl 'localhost:8081/t?RT=62&SID=BC3781C3-2E02-4A11-89CF-34E5CFE8B0EF&UID=44332&L=EN&M=1&H=1&UNC=0&SRC=LK'
M=1&UNC=0&RT=62&H=1&L=EN&SRC=LK

It is worth mentioning that, if you want to retain the order of the URI arguments, then you can do string substitutions on the value of $args directly, for example,

location = /t {
    rewrite_by_lua '
        local args = ngx.var.args
        newargs, n, err = ngx.re.gsub(args, [[\b[SU]ID=[^&]*&?]], "", "jo")
        if n and n > 0 then
            ngx.var.args = newargs
        end
    ';

    echo $args;
}

Now test it with the original curl command again, we get exactly what we would expect:

RT=62&L=EN&M=1&H=1&UNC=0&SRC=LK

But for caching purposes, it's good to normalize the URI argument order so that you can increase the cache hit rate. And the hash table entry order used by LuaJIT or Lua can be used to normalize the order as a nice side effect.

Back to TOC

Directives

Back to TOC

srcache_fetch

syntax: srcache_fetch <method> <uri> <args>?

default: no

context: http, server, location, location if

phase: post-access

This directive registers an access phase handler that will issue an Nginx subrequest to lookup the cache.

When the subrequest returns status code other than 200, than a cache miss is signaled and the control flow will continue to the later phases including the content phase configured by ngx_http_proxy_module, ngx_http_fastcgi_module, and others. If the subrequest returns 200 OK, then a cache hit is signaled and this module will send the subrequest's response as the current main request's response to the client directly.

This directive will always run at the end of the access phase, such that ngx_http_access_module's allow and deny will always run before this.

You can use the srcache_fetch_skip directive to disable cache look-up selectively.

Back to TOC

srcache_fetch_skip

syntax: srcache_fetch_skip <flag>

default: srcache_fetch_skip 0

context: http, server, location, location if

phase: post-access

The <flag> argument supports nginx variables. When this argument's value is not empty and not equal to 0, then the fetching process will be unconditionally skipped.

For example, to skip caching requests which have a cookie named foo with the value bar, we can write

 location / {
     set $key ...;
     set_by_lua $skip '
         if ngx.var.cookie_foo == "bar" then
             return 1
         end
         return 0
     ';

     srcache_fetch_skip $skip;
     srcache_store_skip $skip;

     srcache_fetch GET /memc $key;
     srcache_store GET /memc $key;

     # proxy_pass/fastcgi_pass/content_by_lua/...
 }

where lua-nginx-module is used to calculate the value of the $skip variable at the (earlier) rewrite phase. Similarly, the $key variable can be computed by Lua using the set_by_lua or rewrite_by_lua directive too.

The standard map directive can also be used to compute the value of the $skip variable used in the sample above:

 map $cookie_foo $skip {
     default     0;
     bar         1;
 }

but your map statement should be put into the http config block in your nginx.conf file though.

Back to TOC

srcache_store

syntax: srcache_store <method> <uri> <args>?

default: no

context: http, server, location, location if

phase: output-filter

This directive registers an output filter handler that will issue an Nginx subrequest to save the response of the current main request into a cache backend. The status code of the subrequest will be ignored.

You can use the srcache_store_skip and srcache_store_max_size directives to disable caching for certain requests in case of a cache miss.

Since the v0.12rc7 release, both the response status line, response headers, and response bodies will be put into the cache. By default, the following special response headers will not be cached:

  • Connection
  • Keep-Alive
  • Proxy-Authenticate
  • Proxy-Authorization
  • TE
  • Trailers
  • Transfer-Encoding
  • Upgrade
  • Set-Cookie

You can use the srcache_store_pass_header and/or srcache_store_hide_header directives to control what headers to cache and what not.

The original response's data chunks get emitted as soon as they arrive. srcache_store just copies and collects the data in an output filter without postponing them from being sent downstream.

But please note that even though all the response data will be sent immediately, the current Nginx request lifetime will not finish until the srcache_store subrequest completes. That means a delay in closing the TCP connection on the server side (when HTTP keepalive is disabled, but proper HTTP clients should close the connection actively on the client side, which adds no extra delay or other issues at all) or serving the next request sent on the same TCP connection (when HTTP keepalive is in action).

Back to TOC

srcache_store_max_size

syntax: srcache_store_max_size <size>

default: srcache_store_max_size 0

context: http, server, location, location if

phase: output-header-filter

When the response body length is exceeding this size, this module will not try to store the response body into the cache using the subrequest template that is specified in srcache_store.

This is particular useful when using a cache storage backend that does have a hard upper limit on the input data. For example, the Memcached server has a default limit of 1 MB by item.

When 0 is specified (the default value), there's no limit check at all.

Back to TOC

srcache_store_skip

syntax: srcache_store_skip <flag>

default: srcache_store_skip 0

context: http, server, location, location if

phase: output-header-filter

The <flag> argument supports Nginx variables. When this argument's value is not empty and not equal to 0, then the storing process will be unconditionally skipped.

Starting from the v0.25 release, the <flag> expression (possibly containing Nginx variables) can be evaluated up to twice: the first time is right after the response header is being sent and when the <flag> expression is not evaluated to true values it will be evaluated again right after the end of the response body data stream is seen. Before v0.25, only the first time evaluation is performed.

Here's an example using Lua to set $nocache to avoid storing URIs that contain the string "/tmp":

 set_by_lua $nocache '
     if string.match(ngx.var.uri, "/tmp") then
         return 1
     end
     return 0';

 srcache_store_skip $nocache;

Back to TOC

srcache_store_statuses

syntax: srcache_store_statuses <status1> <status2> ..

default: srcache_store_statuses 200 301 302 307 308

context: http, server, location, location if

phase: output-header-filter

This directive controls what responses to store to the cache according to their status code.

By default, only 200, 301, 302, 307 and 308 responses will be stored to cache and any other responses will skip srcache_store.

You can specify arbitrary positive numbers for the response status code that you'd like to cache, even including error code like 404 and 503. For example:

 srcache_store_statuses 200 201 301 302 307 308 404 503;

At least one argument should be given to this directive.

This directive was first introduced in the v0.13rc2 release.

Back to TOC

srcache_store_ranges

syntax: srcache_store_ranges on|off

default: srcache_store_ranges off

context: http, server, location, location if

phase: output-body-filter

When this directive is turned on (default to off), srcache_store will also store 206 Partial Content responses generated by the standard ngx_http_range_filter_module. If you turn this directive on, you MUST add $http_range to your cache keys. For example,

 location / {
     set $key "$uri$args$http_range";
     srcache_fetch GET /memc $key;
     srcache_store PUT /memc $key;
 }

This directive was first introduced in the v0.27 release.

Back to TOC

srcache_header_buffer_size

syntax: srcache_header_buffer_size <size>

default: srcache_header_buffer_size 4k/8k

context: http, server, location, location if

phase: output-header-filter

This directive controles the header buffer when serializing response headers for srcache_store. The default size is the page size, usually 4k or 8k depending on specific platforms.

Note that the buffer is not used to hold all the response headers, but just each individual header. So the buffer is merely needed to be big enough to hold the longest response header.

This directive was first introduced in the v0.12rc7 release.

Back to TOC

srcache_store_hide_header

syntax: srcache_store_hide_header <header>

default: no

context: http, server, location, location if

phase: output-header-filter

By default, this module caches all the response headers except the following ones:

  • Connection
  • Keep-Alive
  • Proxy-Authenticate
  • Proxy-Authorization
  • TE
  • Trailers
  • Transfer-Encoding
  • Upgrade
  • Set-Cookie

You can hide even more response headers from srcache_store by listing their names (case-insensitive) by means of this directive. For examples,

 srcache_store_hide_header X-Foo;
 srcache_store_hide_header Last-Modified;

Multiple occurrences of this directive are allowed in a single location.

This directive was first introduced in the v0.12rc7 release.

See also srcache_store_pass_header.

Back to TOC

srcache_store_pass_header

syntax: srcache_store_pass_header <header>

default: no

context: http, server, location, location if

phase: output-header-filter

By default, this module caches all the response headers except the following ones:

  • Connection
  • Keep-Alive
  • Proxy-Authenticate
  • Proxy-Authorization
  • TE
  • Trailers
  • Transfer-Encoding
  • Upgrade
  • Set-Cookie

You can force srcache_store to store one or more of these response headers from srcache_store by listing their names (case-insensitive) by means of this directive. For examples,

 srcache_store_pass_header Set-Cookie;
 srcache_store_pass_header Proxy-Autenticate;

Multiple occurrences of this directive are allowed in a single location.

This directive was first introduced in the v0.12rc7 release.

See also srcache_store_hide_header.

Back to TOC

srcache_methods

syntax: srcache_methods <method>...

default: srcache_methods GET HEAD

context: http, server, location

phase: post-access, output-header-filter

This directive specifies HTTP request methods that are considered by either srcache_fetch or srcache_store. HTTP request methods not listed will be skipped completely from the cache.

The following HTTP methods are allowed: GET, HEAD, POST, PUT, and DELETE. The GET and HEAD methods are always implicitly included in the list regardless of their presence in this directive.

Note that since the v0.17 release HEAD requests are always skipped by srcache_store because their responses never carry a response body.

This directive was first introduced in the v0.12rc7 release.

Back to TOC

srcache_ignore_content_encoding

syntax: srcache_ignore_content_encoding on|off

default: srcache_ignore_content_encoding off

context: http, server, location, location if

phase: output-header-filter

When this directive is turned off (which is the default), non-empty Content-Encoding response header will cause srcache_store skip storing the whole response into the cache and issue a warning into nginx's error.log file like this:

[warn] 12500#0: *1 srcache_store skipped due to response header "Content-Encoding: gzip"
            (maybe you forgot to disable compression on the backend?)

Turning on this directive will ignore the Content-Encoding response header and store the response as usual (and also without warning).

It's recommended to always disable gzip/deflate compression on your backend server by specifying the following line in your nginx.conf file:

 proxy_set_header  Accept-Encoding  "";

This directive was first introduced in the v0.12rc7 release.

Back to TOC

srcache_request_cache_control

syntax: srcache_request_cache_control on|off

default: srcache_request_cache_control off

context: http, server, location

phase: post-access, output-header-filter

When this directive is turned on, the request headers Cache-Control and Pragma will be honored by this module in the following ways:

  1. srcache_fetch, i.e., the cache lookup operation, will be skipped when request headers Cache-Control: no-cache and/or Pragma: no-cache are present.
  2. srcache_store, i.e., the cache store operation, will be skipped when the request header Cache-Control: no-store is specified.

Turning off this directive will disable this functionality and is considered safer for busy sites mainly relying on cache for speed.

This directive was first introduced in the v0.12rc7 release.

See also srcache_response_cache_control.

Back to TOC

srcache_response_cache_control

syntax: srcache_response_cache_control on|off

default: srcache_response_cache_control on

context: http, server, location

phase: output-header-filter

When this directive is turned on, the response headers Cache-Control and Expires will be honored by this module in the following ways:

This directive takes priority over the srcache_store_no_store, srcache_store_no_cache, and srcache_store_private directives.

This directive was first introduced in the v0.12rc7 release.

See also srcache_request_cache_control.

Back to TOC

srcache_store_no_store

syntax: srcache_store_no_store on|off

default: srcache_store_no_store off

context: http, server, location

phase: output-header-filter

Turning this directive on will force responses with the header Cache-Control: no-store to be stored into the cache when srcache_response_cache_control is turned on and other conditions are met. Default to off.

This directive was first introduced in the v0.12rc7 release.

Back to TOC

srcache_store_no_cache

syntax: srcache_store_no_cache on|off

default: srcache_store_no_cache off

context: http, server, location

phase: output-header-filter

Turning this directive on will force responses with the header Cache-Control: no-cache to be stored into the cache when srcache_response_cache_control is turned on and other conditions are met. Default to off.

This directive was first introduced in the v0.12rc7 release.

Back to TOC

srcache_store_private

syntax: srcache_store_private on|off

default: srcache_store_private off

context: http, server, location

phase: output-header-filter

Turning this directive on will force responses with the header Cache-Control: private to be stored into the cache when srcache_response_cache_control is turned on and other conditions are met. Default to off.

This directive was first introduced in the v0.12rc7 release.

Back to TOC

srcache_default_expire

syntax: srcache_default_expire <time>

default: srcache_default_expire 60s

context: http, server, location, location if

phase: output-header-filter

This directive controls the default expiration time period that is allowed for the $srcache_expire variable value when neither Cache-Control: max-age=N nor Expires are specified in the response headers.

The <time> argument values are in seconds by default. But it's wise to always explicitly specify the time unit to avoid confusion. Time units supported are "s"(seconds), "ms"(milliseconds), "y"(years), "M"(months), "w"(weeks), "d"(days), "h"(hours), and "m"(minutes). For example,

 srcache_default_expire 30m; # 30 minutes

This time must be less than 597 hours.

The semantics of a zero expiration time depends on the actual cache backend storage you are currently using, which is agnostic to this module. In the case of memcached, for example, zero expiration times mean that the item will never expire.

This directive was first introduced in the v0.12rc7 release.

Back to TOC

srcache_max_expire

syntax: srcache_max_expire <time>

default: srcache_max_expire 0

context: http, server, location, location if

phase: output-header-filter

This directive controls the maximal expiration time period that is allowed for the $srcache_expire variable value. This setting takes priority over other calculating methods.

The <time> argument values are in seconds by default. But it's wise to always explicitly specify the time unit to avoid confusion. Time units supported are "s"(seconds), "ms"(milliseconds), "y"(years), "M"(months), "w"(weeks), "d"(days), "h"(hours), and "m"(minutes). For example,

 srcache_max_expire 2h;  # 2 hours

This time must be less than 597 hours.

When 0 is specified, which is the default setting, then there will be no limit at all.

This directive was first introduced in the v0.12rc7 release.

Back to TOC

Variables

Back to TOC

$srcache_expire

type: integer

cacheable: no

writable: no

This Nginx variable gives the recommended expiration time period (in seconds) for the current response being stored into the cache. The algorithm of computing the value is as follows:

  1. When the response header Cache-Control: max-age=N is specified, then N will be used as the expiration time,
  2. otherwise if the response header Expires is specified, then the expiration time will be obtained by subtracting the current time stamp from the time specified in the Expires header,
  3. when neither Cache-Control: max-age=N nor Expires headers are specified, use the value specified in the srcache_default_expire directive.

The final value of this variable will be the value specified by the srcache_max_expire directive if the value obtained in the algorithm above exceeds the maximal value (if any).

You don't have to use this variable for the expiration time.

This variable was first introduced in the v0.12rc7 release.

Back to TOC

$srcache_fetch_status

type: string

cacheable: no

writable: no

This Nginx variable is evaluated to the status of the "fetch" phase for the caching system. Three values are possible, HIT, MISS, and BYPASS.

When the "fetch" subrequest returns status code other than 200 or its response data is not well-formed, then this variable is evaluated to the value MISS.

The value of this variable is only meaningful after the access request processing phase, or BYPASS is always given.

This variable was first introduced in the v0.14 release.

Back to TOC

$srcache_store_status

type: string

cacheable: no

writable: no

This Nginx variable gives the current caching status for the "store" phase. Two possible values, STORE and BYPASS can be obtained.

Because the responses for the "store" subrequest are always discarded, so the value of this variable will always be STORE as long as the "store" subrequest is actually issued.

The value of this variable is only meaningful at least when the request headers of the current (main) request are being sent. The final result can only be obtained after all the response body has been sent if the Content-Length response header is not specified for the main request.

This variable was first introduced in the v0.14 release.

Back to TOC

Known Issues

Back to TOC

Caveats

  • It is recommended to disable your backend server's gzip compression and use nginx's ngx_http_gzip_module to do the job. In case of ngx_http_proxy_module, you can use the following configure setting to disable backend gzip compression:
 proxy_set_header  Accept-Encoding  "";
 map $request_method $skip_fetch {
     default     0;
     POST        1;
     PUT         1;
 }

 server {
     listen 8080;

     location /api/ {
         set $key "$uri?$args";

         srcache_fetch GET /memc $key;
         srcache_store PUT /memc $key;

         srcache_methods GET PUT POST;
         srcache_fetch_skip $skip_fetch;

         # proxy_pass/drizzle_pass/content_by_lua/echo/...
     }
 }

Back to TOC

Trouble Shooting

To debug issues, you should always check your Nginx error.log file first. If no error messages are printed, you need to enable the Nginx debugging logs to get more details, as explained in debugging log.

Several common pitfalls for beginners:

  • The original response carries a Cache-Control header that explicitly disables caching and you do not configure directives like srcache_response_cache_control.
  • The original response is already gzip compressed, which is not cached by default (see srcache_ignore_content_encoding).
  • Memcached might return CLIENT_ERROR bad command line format when using a too long key (250 chars as of version 1.4.25). It is thus safer to use set_md5 $key $uri$args; instead of set $key $uri$args;. The set_md5 directive (and more) is available from OpenResty's set-misc module.
  • Nginx might return client intended to send too large body when trying to store objects larger than 1m to the storage backend, in which case nginx client_max_body_size must be set to a higher value.
  • Memcached might fail to store objects larger than 1m, causing errors like srcache_store subrequest failed status=502. Since version 1.4.2, memcached supports a command-line -I option to override the default size of each slab page. Please read its manpage for more information.

Back to TOC

Installation

It is recommended to install this module as well as the Nginx core and many other goodies via the OpenResty bundle. It is the easiest way and most safe way to set things up. See OpenResty's installation instructions for details.

Alternatively, you can build Nginx with this module all by yourself:

 wget 'http://nginx.org/download/nginx-1.9.15.tar.gz'
 tar -xzvf nginx-1.9.15.tar.gz
 cd nginx-1.9.15/

 # Here we assume you would install you nginx under /opt/nginx/.
 ./configure --prefix=/opt/nginx \
      --add-module=/path/to/srcache-nginx-module

 make -j2
 make install

Starting from NGINX 1.9.11, you can also compile this module as a dynamic module, by using the --add-dynamic-module=PATH option instead of --add-module=PATH on the ./configure command line above. And then you can explicitly load the module in your nginx.conf via the load_module directive, for example,

load_module /path/to/modules/ngx_http_srcache_filter_module.so;

Back to TOC

Compatibility

The following versions of Nginx should work with this module:

  • 1.9.x (last tested: 1.9.15)
  • 1.8.x
  • 1.7.x (last tested: 1.7.10)
  • 1.5.x (last tested: 1.5.12)
  • 1.4.x (last tested: 1.4.4)
  • 1.3.x (last tested: 1.3.7)
  • 1.2.x (last tested: 1.2.9)
  • 1.1.x (last tested: 1.1.5)
  • 1.0.x (last tested: 1.0.11)
  • 0.9.x (last tested: 0.9.4)
  • 0.8.x >= 0.8.54 (last tested: 0.8.54)

Earlier versions of Nginx like 0.7.x, 0.6.x and 0.5.x will not work.

If you find that any particular version of Nginx above 0.7.44 does not work with this module, please consider reporting a bug.

Back to TOC

Community

Back to TOC

English Mailing List

The openresty-en mailing list is for English speakers.

Back to TOC

Chinese Mailing List

The openresty mailing list is for Chinese speakers.

Back to TOC

Bugs and Patches

Please submit bug reports, wishlists, or patches by

  1. creating a ticket on the GitHub Issue Tracker,
  2. or posting to the OpenResty community.

Back to TOC

Source Repository

Available on github at openresty/srcache-nginx-module.

Back to TOC

Test Suite

This module comes with a Perl-driven test suite. The test cases are declarative too. Thanks to the Test::Nginx module in the Perl world.

To run it on your side:

 $ PATH=/path/to/your/nginx-with-srcache-module:$PATH prove -r t

You need to terminate any Nginx processes before running the test suite if you have changed the Nginx server binary.

Because a single nginx server (by default, localhost:1984) is used across all the test scripts (.t files), it's meaningless to run the test suite in parallel by specifying -jN when invoking the prove utility.

Some parts of the test suite requires modules ngx_http_rewrite_module, echo-nginx-module, rds-json-nginx-module, and drizzle-nginx-module to be enabled as well when building Nginx.

Back to TOC

TODO

  • add gzip compression and decompression support.
  • add new nginx variable $srcache_key and new directives srcache_key_ignore_args, srcache_key_filter_args, and srcache_key_sort_args.

Back to TOC

Getting involved

You'll be very welcomed to submit patches to the author or just ask for a commit bit to the source repository on GitHub.

Back to TOC

Author

Yichun "agentzh" Zhang (章亦春) [email protected], CloudFlare Inc.

Back to TOC

Copyright & License

Copyright (c) 2010-2016, Yichun "agentzh" Zhang (章亦春) [email protected], CloudFlare Inc.

This module is licensed under the terms of the BSD license.

Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:

  • Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
  • Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Back to TOC

See Also

Back to TOC

srcache-nginx-module's People

Contributors

agentzh avatar chipitsine avatar hnakamur avatar kapouer avatar kylebevans avatar mattltw avatar onnimonni avatar perlover avatar piotrsikora avatar thibaultcha avatar xiaocang avatar zhuizhuhaomeng avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

srcache-nginx-module's Issues

Please correct doc :)

My English is not good so i will not do a pull request

README.markdown -> Caveats -> "So it's necessary to use the charset, default_type and add_header directives ..."

I work with your module now and noticed that default_type in location where are too your directives is used by nginx only if response from proxy_pass (or static files too) doesn't match with mime extensions by last suffix from mime.types config
For example if i have a following config:

  location / {
      default_type  application/octet-stream;
      proxy_pass         http://proxy_address;
      ....
  set $key $http_host$uri;
  set_md5 $key;
  srcache_fetch GET /memc $key;
  srcache_store PUT /memc $key;
  expires      12h;
  }

For images (*.jpg) i will have image/jpeg
I think this http header is set up by local nginx if object is in cache already (nginx see that there are no content type and he looks for mime.type config file)

I think this is needed to be in docs because somebody can stop to use your module if he will think that he should describe every locations for each mime type

Thanks

help for srcache with redis for elgg

hello ..
i am trying to setup nginx with redis for elgg 1.11...
it is working fine but suffering below issue
login and logout not working....

here i attached mine nginx conf file.

nginx.txt

Might be an error in the redis example

Hi

Should the line redis_pass 127.0.0.1:6379;
be redis2_pass 127.0.0.1:6379; ?

We've been testing with the first variant, but not sure if its optimal.

compute a $storeKey for srcache_store after upstream response ?

Hi,
i'm trying to implement HTTP Vary with srcache.
A typical upstream response will contain a Vary: Accept-Language field,
header_filter_by_lua_block could then

  1. compute a $storeKey by concatenation of key/value of request fields listed in that Vary header
  2. store url => Vary field in a shared dict
    (Upon later request, set_by_lua_block could compute a $requestKey by looking up
    in the shared dict to get the list of Vary headers for the requested url.)

Question: is it possible to make srcache_store use $storeKey and not preprocessed key ?

set_hashed_upstream in examples - incorrect?

srcache-nginx-module / README.markdown

There is your example:

location = /memc {
    internal;

    set $memc_key $query_string;
    set_hashed_upstream $backend universe $memc_key;
    set $memc_exptime 3600; # in seconds
    memc_pass $backend;
}

location / {
    set $key $uri;
    srcache_fetch GET /memc $key;
    srcache_store PUT /memc $key;

    # proxy_pass/fastcgi_pass/content_by_lua/drizzle_pass/...
}

I can make a mistake but i think that there is a potential issue here:
set $memc_key $query_string;
set_hashed_upstream $backend universe $memc_key;

I think for GET & PUT memcached's request there will be different $query_string's
And for same $uri's in "location /" will be different $memc_key variable for GET & PUT requests.
And set_hashed_upstream will set different $backend's for GET and for PUT request.
I think there will be trashing of upstream servers: for GET requests of URI $backend will be A for example but for PUT requests will be $backend as B

How do you think?

Thanks :)

A queue for multiple simultaneous request to the same content.

I am trying to use srchache + redis as a replacement of varnish as srcache gives the opportunity of having shared cache. However, there is one thing that I am missing. Let me describe a simple scenario.

We have 1000 concurrent users on the front page. We need to flush the redis cache for some reason. When the cache is empty each of the concurrent request for same content (same cache key) will be sent to the backend which might result in beckend failure.

It would be great is srcache support some queue for multiple requests to the same content just like proxy_cache, so the load to the backed is reduced.

@see: https://www.nginx.com/resources/admin-guide/content-caching/#slice
“Sometimes, the initial cache fill operation may take some time, especially for large files. When the first request starts downloading a part of a video file, next requests will have to wait for the entire file to be downloaded and put into the cache.”

Help with configuration of specific folder

Hi!

As i mentioned earlier im using srcache to serve assets like css/js/img.

My application does the mapping and generates URLs like:

http://frontdoor.ricardo/gimme/a04da9f9fd/pkg/css/index.css
http://frontdoor.ricardo/gimme/e82d990d14/js/backbone.js

So im trying to set srcache to just this folder: /gimme

Here is my config:

upstream memcached {
    server    127.0.0.1:11211;
    #keepalive 1024 single;
}

# frontdoor
server {
    server_name frontdoor.*;

#   memc_connect_timeout 100ms;

    root   /Users/ricardo/Sites/frontdoor/www;

    fastcgi_read_timeout 3600;

    location = /memc {
        internal;

        memc_connect_timeout 250ms;
        memc_send_timeout 250ms;
        memc_read_timeout 250ms;

        set $memc_key $query_string;
        set $memc_exptime 0; # never expires

        memc_pass memcached;
    }

    location / {            
        try_files $uri /index.php$is_args$args;
    }

    location /gimme {
        set $key $http_host$request_uri;
        srcache_fetch GET /memc $key;
        srcache_store PUT /memc $key;
        srcache_store_statuses 200 301 302 304 404;

        try_files $uri /index.php$is_args$args;
    }

    location ~ \.php$ {     
        include        fastcgi.conf;
        fastcgi_pass   localhost:9000;
    }
}

This way it does not write to memcached and its a miss everytime. If i move the srcache stuff to inside the location ~ .php$ it will work, but i do not want the overhead of lookup in requests outside the /gimme folder.

Can you help me to do it the best way possible?

Thx

proxy_cache_use_stale like directive

the proxy_cache_use_stale directive can determines in which cases a stale cached response can be used when an error occurs during communication with the proxied server.

but when i using srcache+redis, the reids always delete keys...

srcache wont cache

I tried for many hours to solve this on my own without avail. I tested nginx version 1.4.0 and 1.3.11 neither worked. I also ignored all headers that could interfere. No matter what I try I am only able to get a fetch MISS and store BYPASS.

debug log (grep srcache): http://pastebin.com/4c9FnvJw
nginx -V: http://pastebin.com/2WkAF62Y
config sample 1: http://pastebin.com/n7tyf5bx
config sample 2: http://pastebin.com/rCSxY1Bh

in sample 2 I tried adding everything that I could think of to rule out any error with the backend (content-encoding etc). The page being proxied is http://www.x4b.org/main.1364042305.css

Confirmation of method

Ok firstly im sorry if this is documented anywhere, I couldn't find it. Its a question regarding the way srcache_store works, which may turn into a feature request.

Basically I run a cross datacenter slave system. PUT requests require writing to a master server which can be up to 100ms in latency away. Our system depends on low latency serving of requests.

Does srcache_store, when waiting on a response block the request from being outputted?

$srcache_expire is always empty

Hey!

I have been trying srcache with redis for few weeks now and today I noticed that the cache keys are not expiring automatically.

I'm using this config in local docker environment:

##
# Adds internal locations for storing and getting full page cache from redis
##

srcache_default_expire 10s;
srcache_max_expire 10s;

location /redis-fetch {
    internal;

    ##
    # In order to use password authentication we use custom redis module which adds $redis_auth:
    # - https://github.com/Yongke/ngx_http_redis-0.3.7
    ##

    # Read the configuration from system envs
    set $redis_auth '';
    set $redis_db 0;

    set $redis_key $args;

    redis_pass 172.17.0.6:6379;
}

location /redis-store {
    internal;

    set_unescape_uri $exptime $arg_exptime;
    set_unescape_uri $key $arg_key;

    # redis module pipelines these 3 commands into single request
    redis2_query auth '';
    redis2_query select 0;
    redis2_query set $key $echo_request_body;
    redis2_query expire $key $srcache_expire;

    # Pass the request to redis
    redis2_pass 172.17.0.6:6379;

}

Then I open redis-cli to monitor incoming requests:

$ redis-cli
> monitor
1478704802.63890 [0 172.17.0.8:54906] "select" "0"
1478704802.638100 [0 172.17.0.8:54906] "get" "wp_:nginx:httpsGETwordpress.test/robots.txt"
1478704802.638122 [0 172.17.0.8:54900] "auth" ""
1478704802.638137 [0 172.17.0.8:54900] "select" "0"
1478704802.638148 [0 172.17.0.8:54900] "set" "wp_:nginx:httpsGETwordpress.test/robots.txt" "HTTP/1.1 200 OK\r\nContent-Type: text/plain; charset=utf-8\r\nExpires: Thu, 19 Nov 1981 08:52:00 GMT\r\nCache-Control: no-store, no-cache, must-revalidate\r\nPragma: no-cache\r\nX-Robots-Tag: noindex, follow\r\nLink: <https://wordpress.test/wp-json/>; rel=\"https://api.w.org/\"\r\nLink: <https://wordpress.test/wp-json>; rel=\"https://github.com/WP-API/WP-API\"\r\nX-Cache: MISS\r\n\r\nUser-agent: *\nDisallow: /wp-admin/\nAllow: /wp-admin/admin-ajax.php\n"
1478704802.638189 [0 172.17.0.8:54900] "expire" "wp_:nginx:httpsGETwordpress.test/robots.txt" ""

And where I should see 10s because of the srcache_max_expire directive or 0 because of the Cache-Control: no-store, no-cache, must-revalidate header instead I see "" as sent to redis.

Version:

nginx -V
nginx version: openresty/1.11.2.1
built by gcc 4.9.2 (Debian 4.9.2-10)
built with OpenSSL 1.0.2j  26 Sep 2016
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx/nginx --with-cc-opt=-O2 --add-module=../ngx_devel_kit-0.3.0 --add-module=../echo-nginx-module-0.60 --add-module=../xss-nginx-module-0.05 --add-module=../ngx_coolkit-0.2rc3 --add-module=../set-misc-nginx-module-0.31 --add-module=../form-input-nginx-module-0.12 --add-module=../encrypted-session-nginx-module-0.06 --add-module=../srcache-nginx-module-0.31 --add-module=../ngx_lua-0.10.6 --add-module=../ngx_lua_upstream-0.06 --add-module=../headers-more-nginx-module-0.31 --add-module=../array-var-nginx-module-0.05 --add-module=../memc-nginx-module-0.17 --add-module=../redis2-nginx-module-0.13 --add-module=../rds-json-nginx-module-0.14 --add-module=../rds-csv-nginx-module-0.07 --with-ld-opt=-Wl,-rpath,/etc/nginx/luajit/lib --with-http_addition_module --with-http_auth_request_module --with-http_flv_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_mp4_module --with-http_random_index_module --with-http_realip_module --with-http_secure_link_module --with-http_slice_module --with-http_ssl_module --with-http_stub_status_module --with-http_sub_module --with-http_v2_module --with-http_geoip_module=dynamic --with-file-aio --with-ipv6 --with-pcre-jit --with-stream --with-stream_ssl_module --with-threads --without-http_autoindex_module --without-http_browser_module --without-http_userid_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --without-http_split_clients_module --without-http_uwsgi_module --without-http_scgi_module --without-http_referer_module --user=nginx --group=nginx --sbin-path=/usr/sbin --modules-path=/usr/lib/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx/nginx.lock --http-fastcgi-temp-path=/tmp/nginx/fastcgi --http-proxy-temp-path=/tmp/nginx/proxy --http-client-body-temp-path=/tmp/nginx/client_body --add-module=/tmp/ngx_http_redis-0.3.7-master --add-module=/tmp/ngx_pagespeed-1.11.33.4-beta --with-openssl=/tmp/openssl-1.0.2j

What to use for SSI/ESI like feature?

Hello,

I am working on a project where I need an SSI/ESI like feature. For full page cache I am now using the srcache-nginx-module with Redis and a PHP backend. There will be at least 3 blocks per page which I need whole-punched with something like SSI/ESI and these will also be cached.

SSI does not play well with Lua, on the other hand if I am using SSI with srcache_fetch only then it won't work on my sub-requests.

What would be a good (elegant and also performance wise) approach to replace SSI/ESI tags in both the backend and srcache_fetch responses? Liked replace-filter-nginx-module, but it does not support Lua replacements which I need.

I've done some research and testing, but none worked so far:

  • Use a template engine - no buffer and how to process cached responses
  • use body_filter_by_lua would fail when chunk ends in the middle of a placeholder

Thank you in advance!

Save gzip and normal version

Hi!

FIrst of all, really GREAT work. Im using it with our js/css packer and it is working really great cause the URLs are hashed so I can store the requests on memcached forever and all automatically. With just memc module i was having to write the assets to memcached in the application backend and i did not like it.

In your TODO it is written Gzip. So i would like to see if it checks with what i would like:

Now im using Nginx Gzip Module to gzip css/js/html on the fly, after it comes from srcache or backend. If srcache could save a gzip version of the content it could be served directlly. What doesnt go in srcache would still be gzipped on the fly.

Not that it is necessary to save a not gzipped version to save IE6. You could even read the gzip_disable var.

Is that the way you are thinking?

Thx and keep the great work!

srcache_fetch GET with redis2_query and hget

Hi There,

I'm trying to use srcache_fetch with Redis2 module via redis2_query and not with the old HTTP REDIS module.
I have 2 issues and they might be related.

  1. When I'm using redis2 module and not HTTP REDIS in the srcache_fetch directive I never get a good response.
    Working Example:
    srcache_fetch GET /redis $key;
    location = /redis {
    internal;
    set $redis_key $args;
    redis_pass redisbackend_read;
    }

Non-Working Example:
srcache_fetch GET /redis $key;
location = /redis {
internal;
redis2_query get $args
redis2_pass redisbackend_read;
}

My Upstream backend for both examples is:
upstream redisbackend_read {
server 127.0.0.1:6379
keepalive 1024;
}

I can see that both queries are getting to Redis(I can see in in the Monitor), but when using redis2 it seems like the response is not valid or something because I'm redirected to the backend like the key can't be found.

In the working example there are no errors in the log file but in the non working example with redis2 I can see the following:
2016/02/09 15:25:54 [error] 25052#0: *1 srcache_fetch: cache sent invalid status line while sending to client, client: 192.168.56.2, server: _, request: "GET /api/adserver/tag?AV_PUBLISHERID=55b88d4a181f465b3e8b4567&AV_CHANNELID=55f030e7181f46b9228b4572 HTTP/1.1", subrequest: "/redis", upstream: "redis2://127.0.0.1:6379", host: "aniview"
2016/02/09 15:25:54 [error] 25052#0: *1 srcache_fetch: cache sent truncated response body while sending to client, client: 192.168.56.2, server: _, request: "GET /api/adserver/tag?AV_PUBLISHERID=55b88d4a181f465b3e8b4567&AV_CHANNELID=55f030e7181f46b9228b4572 HTTP/1.1", subrequest: "/redis", upstream: "redis2://127.0.0.1:6379", host: "aniview"

Basically I'm trying to use hget against Redis but as I saw that even regular get doesn't work with redis2 module then I think that my issues with hget will be addressed if we can understand what happening here.

NGINX -V output:
nginx version: nginx/1.8.0
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-16) (GCC)
built with OpenSSL 1.0.1e-fips 11 Feb 2013
TLS SNI support enabled
configure arguments: --prefix=/etc/nginx --sbin-path=/usr/sbin/nginx --conf-path=/etc/nginx/nginx.conf --error-log-path=/var/log/nginx/error.log --http-log-path=/var/log/nginx/access.log --pid-path=/var/run/nginx.pid --lock-path=/var/run/nginx.lock --http-client-body-temp-path=/var/cache/nginx/client_temp --http-proxy-temp-path=/var/cache/nginx/proxy_temp --http-fastcgi-temp-path=/var/cache/nginx/fastcgi_temp --http-uwsgi-temp-path=/var/cache/nginx/uwsgi_temp --http-scgi-temp-path=/var/cache/nginx/scgi_temp --user=nginx --group=nginx --add-module=/usr/src/ngx_http_geoip2_module-1.0 --add-module=/usr/src/nginx-ua-parse-module --with-http_ssl_module --with-http_realip_module --with-http_sub_module --with-http_dav_module --with-http_gunzip_module --with-http_gzip_static_module --with-file-aio --with-ipv6 --with-http_spdy_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --add-module=/usr/src/ngx_http_lower_upper_case --add-module=/usr/src/ngx_http_redis-0.3.7 --add-module=/usr/src/lua-nginx-module-0.9.20 --add-module=/usr/src/redis2-nginx-module-0.12 --add-module=/usr/src/ngx_devel_kit-0.2.19 --add-module=/usr/src/headers-more-nginx-module-0.261 --add-module=/usr/src/set-misc-nginx-module-0.28 --add-module=/usr/src/echo-nginx-module-0.57 --add-module=/usr/src/array-var-nginx-module-0.04 --add-module=/usr/src/strftime-nginx-module --add-module=/usr/src/srcache-nginx-module-0.29

More information from redis for both examples which one works and the other one does not work is:
I'm setting the value this way:
"set" "zc:k:db6cf5e91987f48d521e85474750b2ca" "HTTP/1.1 200 OK\r\nContent-Type: text/html\r\nX-Powered-By: PHP/5.5.32\r\n\r\n"

Any help and investigation will be really appreciated.

Request for variables to use in logging and/or headers

As a lot of people have already said, this is a fantastic nginx module - and I agree, many thanks.

I am currently using it with a couchbase server and will eventually extend to running multiple nginx caches behind a couchbase cluster on a loadbalancer (or more).

I have been trying to obtain a way to get the method srcache used to serve the content.

That is cache HIT/MISS/STORE so I can include either a header and/or cache logging.

I would ultimately like to log bytes sent during a cache hit so I can calculate a monthly usage to graph along side apache monthly usage to give a comparison.

Is this already possible?

srcache_store subrequest failed

Hi,
我目前正在使用openresty 1.7.7.1,逻辑如下:request的uri得到缓存key,先判断这个key在memcached集群中是否有对应的response,如果没有,则通过proxy_pass转到backend_api,得到backend_api的结果然后当作response返回给client,同时store到memcached集群.这样的话,下次同样的request过来之后,直接就可以从memcached获取response.
  但现在在线上运行一段时间之后,得到的错误信息如下:
   srcache_store subrequest failed: rc=502 status=0 while sending to client, client: xxx.xxx.xxx.xxx, server: xxx.com, request: "GET /test?code=W7WSoSBZOIM HTTP/1.1", subrequest: "/memc", host: "xxx.com"

nginx的配置如下:
upstream memc_backend {
hash $arg_key consistent;
server 127.0.0.1:11211;
server 127.0.0.1:11212;
server 127.0.0.1:11213;
server 127.0.0.1:11214;
keepalive 1024;
}
server {
  location = /memc {
    internal;
    memc_connect_timeout 100ms;
    memc_send_timeout 100ms;
    memc_read_timeout 100ms;
    memc_ignore_client_abort on;
    set $memc_key $arg_key;
    set $memc_exptime $arg_exptime;
    memc_pass memc_backend;
  }

  location = /test {
set_by_lua_file $key conf/lua/test/k_get_cache_key.lua;
if ($http_is_update_cache = "Yes") {
srcache_fetch DELETE /memc key=$key;
}
set $exptime 3600;
srcache_fetch GET /memc key=$key;
srcache_store PUT /memc key=$key&exptime=$exptime;
proxy_pass http://backend_api;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Real-IP $x_remote_addr;
proxy_set_header Host $proxy_host;
proxy_set_header Range $http_range;
proxy_set_header X-NginX-Proxy true;
}
}  
能帮忙看下原因么?我已经查了一段时间了,还是没有头绪~~

send 304 header by this module

i make one location, to using lua code, and check the Etag to send 304 status code.
but when i use this module to cache this location, it always hit the cache, and send 200 status code, also send the body every time.

Forward to named route or rewrite?

Hello,

How can I forward requests that did not match any cached entry to a named route?

I have something like:

location / {
    try_files $uri $uri/ @backend;
}

location @backend {
    rewrite / /index.php;
}

location ~ \.php$ {
    # catch 404s
    if (!-e $request_filename) { rewrite / /index.php last; }

    expires off;
    fastcgi_pass 127.0.0.1:9000;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    include fastcgi_params;
}

Should I place srcache_fetch and srcache_store in location / or @backend? Are there any issues if the fallback is try_files or rewrite?

Thank you in advance!

Why still get into srcache_store handler even if $srcache_expire=0?

I just put my srcache settings directly under server block:

server {
    set $canonical_host www.example.com;

    # ...

    srcache_default_expire 0;
    set_escape_uri $pagecache_key $canonical_host$uri$is_args$args;
    srcache_fetch GET /pagecache key=$pagecache_key;
    srcache_store PUT /pagecache key=$pagecache_key&exptime=$srcache_expire;
    include srcache_status_headers;

    # ...
}

You see, I use srcache_default_expire, So the $srcache_expire will default to 0,
I expect my upstream setting their appropriate exptime by max-age.

However, my srcache_store get involved even if $srcache_expire==0,
and then cause an extra useless redis request.

location = /redis_put {
    # tested OK with SSDB
    internal;
    set_unescape_uri $exptime $arg_exptime;

    redis2_query setx $redis_key $echo_request_body $exptime;

    redis2_pass pagecache_ssdb;
}

1.5.x issues

I am not sure where to start with this issue (whose module is at fault). Since the most common error has srcache_fetch in it I am assuming it starts there.

Since upgrading to 1.5.6 we have been seeing many problems -
2013/11/28 01:53:33 [error] 25107#0: *421 srcache_fetch: cache sent truncated status line or headers while sending to client, client: 108.162.219.227, server: www.highway.cf, request: "GET /shop/img/chat.png HTTP/1.1", subrequest: "/___redis__read", upstream: "redis://X:6380",

and occasionally

2013/11/28 01:54:48 [error] 25107#0: *1127 redis sent invalid trailer while sending to client, client: 14.203.10.166, server: , request: "GET /images/logo.png HTTP/1.1", subrequest: "/___redis__read", upstream: "redis://X:6380", host:

Modules installed -
redis (0.3.6)
latest git - redis2, misc, srcache, echo
patches - none

Related config:
srcache_default_expire 60m;
srcache_store_statuses 200;
srcache_store_max_size 10m;
srcache_request_cache_control off;
set_escape_uri $escaped_key "ID$request_method|$scheme://*$request_uri";
srcache_fetch GET /___redis__read key=$escaped_key;
srcache_store PUT /___redis__write key=$escaped_key&exptime=$srcache_expire;

location = /___redis__read {
internal;
set_unescape_uri $redis_key $arg_key;
redis_pass redis_proxy;
}

location = /___redis__write {
internal;
set_unescape_uri $exptime $arg_exptime;
set_unescape_uri $key $arg_key;
redis2_query set $key $echo_request_body;
redis2_query expire $key $exptime;
redis2_pass redis_proxy;
}

We have had no previous issues with this config on 1.4.x (with upstream truncation patch).

Ideas?

srcache cant work with nginx slice option not stored

Hello
sorry I cant memcached requests
I need to slice responce from upstream by slice 1m;

server {
listen front.network;
server_name cdn.cdntest.com;

     location = /memc {
         internal;
         memc_connect_timeout 100ms;
         memc_send_timeout 100ms;
         memc_read_timeout 100ms;
         memc_ignore_client_abort on;
         set $memc_key $query_string;
         set $memc_exptime 3600;

         memc_pass ram1;
     }


     location / {
         slice  1m;

         set $key $uri$is_args$args$slice_range;
         #set $key $uri$args$slice_range;
         srcache_fetch GET /memc $key;
         srcache_store PUT /memc $key;

         srcache_store_ranges on;
         srcache_store_statuses 200 206 301 302;
         srcache_ignore_content_encoding on;

         proxy_set_header  Range $slice_range;
         proxy_pass http://www.cdntest.com;
     }
 }

but in error.log I got
srcache_store: skipped because response body truncated: 149616567 > 1048576 while sending to client

Ctrl + F5 in browser -> need request

Good day!

Can i ask a new useful feature?
Now if object in cache your module will always fetch this object from memcached even if i will press Ctrl + F5 in browser
when i press Ctrl + F5 in Firefox for example the Firefox do a request with "Pragma: no-cache" in http request.
A common proxies and caches should fetch a an object not from cache.

Can i ask to add TODO:

If in request there is "Pragma: no-cache" http header then an answer we should do as object is missed in memcached?

If this feature will be an owner will be able to remove any object by Ctrl + F5 if object was deleted at original location

Thanks! :)

srcache_fetch subrequest return 405 error code.

Hi, We're running into the issue that I always get resonse from upstream, not from redis cache.

And with some debug info, I found that my srcache_fetch subrequest always return 405 error code.

I using POST method with my request and I got problem. but I got correct response from redis cache with GET method.

Here is my nginx configuration.

upstream redis_pools {
    server 192.168.56.110:6379;
    keepalive 1024;
}

upstream search_tds_backend {
    server 172.26.1.118:80 max_fails=3;
    server 172.26.1.120:80 max_fails=3;
}

server {
    listen       80 default_server;
    server_name  localhost;

    redis2_connect_timeout  100ms;
    redis2_send_timeout     100ms;
    redis2_read_timeout     100ms;
    redis_connect_timeout   100ms;
    redis_send_timeout      100ms;
    redis_read_timeout      100ms;

    srcache_methods POST GET;

    location = /redis_cache_get {
        internal;
        set_unescape_uri $key $arg_key;
        set_md5 $key;
        set $redis_key $key;
        redis_gzip_flag 1;
        add_header X-Cache-From "has-cached";
        redis_pass redis_pools;
    }

    location = /redis_cache_set {
        internal;
        set_unescape_uri $exptime $arg_exptime;
        set_unescape_uri $key $arg_key;
        set_md5 $key;
        redis2_query set $key $echo_request_body;
        redis2_query expire $key $exptime;
        redis2_pass redis_pools;
    }

    location / {
        default_type application/json;

        if ($request_method = GET) {
            srcache_fetch GET /redis_cache_get key=$escaped_key&exptime=3600;
        }

        if ($request_method = POST) {
            srcache_fetch POST /redis_cache_get key=$escaped_key&exptime=3600;
        }

        set $key $uri;
        set_escape_uri $escaped_key $key;
        srcache_store POST /redis_cache_set key=$escaped_key&exptime=3600;

        proxy_pass http://search_tds_backend;
        proxy_set_header  Host "se.beta.hq.hiiir";
        add_header X-Cache-From "no-cached";
    }
}

And this is my debug info : http://pastebin.com/hbbbNuj5

So Can you confirm is this srcache_fetch bug or just my configuration mistake or misuse?

Thank you.

Supporting Subrequests

Just ran into this while using ngx.location.capture.

"For subrequests, we explicitly disallow the use of this module because it's not working (yet)."

Are you planning to implement this soon? Is a bounty needed?

Thanks.

memcached down

Hi
If the memcached server is down the very strange output is generated and I have no idea to control it by the module. Expected behaviour is to pass request to proxy without cache requesting.

srcache version: 0.12rc5

Nginx conf:

upstream storage {
  server localhost:8081;
}

upstream memcached {
  server localhost:11211;
  keepalive 512;
}

server {
    # Get static content from storage (control center) via memcached caching
    location /storage {
        set $key $uri;
        srcache_fetch GET /memc key=$key;
        srcache_store PUT /memc key=$key;
        proxy_pass http://storage;
    }

    location = /memc {
        internal;
        set $memc_key $arg_key;
        set $memc_exptime 10;
        memc_pass memcached;
    }

    # redirect server error pages to the static page /50x.html
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   html;
    }

Request:

curl -v http://localhost:8080/1001/1000/1.png

If memcached is up I have my .phg picture

If memcached is down the result is:

> GET /1001/1000/1.png HTTP/1.1
> User-Agent: curl/7.21.6 (x86_64-pc-linux-gnu) libcurl/7.21.6 OpenSSL/1.0.0e zlib/1.2.3.4 libidn/1.22 librtmp/2.3
> Host: localhost:8080
> Accept: */*
>
<html>
<head>
<title>The page is temporarily unavailable</title>
<style>
body { font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body bgcolor="white" text="black">
<table width="100%" height="100%">
<tr>
<td align="center" valign="middle">
The page you are looking for is temporarily unavailable.<br/>
Please try again later.
</td>
</tr>
</table>
</body>
</html>
HTTP/1.1 200 OK
Server: nginx/1.0.4
Date: Tue, 06 Mar 2012 08:54:00 GMT
Content-Type: image/png
Connection: keep-alive
Last-Modified: Thu, 18 Nov 2010 14:37:40 GMT
ETag: "40000a6a-8ca-49554bb626c14"
Accept-Ranges: bytes
Content-Length: 2250

�PNG
......  picture data  ......
<html>
<head>
<title>The page is temporarily unavailable</title>
<style>
body { font-family: Tahoma, Verdana, Arial, sans-serif; }
</style>
</head>
<body bgcolor="white" text="black">
<table width="100%" height="100%">
<tr>
<td align="center" valign="middle">
The page you are looking for is temporarily unavailable.<br/>
Please try again later.
</td>
</tr>
</table>
</body>
</html>
* Connection #0 to host localhost left intact
* Closing connection #0

Storing > 1MB objects in memcached is actually possible

Typically with memcached -I 10m.
It seems to also require nginx client_max_body_size 10M;, or else i get

client intended to send too large body: 1222117 bytes, client: 127.0.0.1, server: , request: "GET /css/semantic.css HTTP/1.1", subrequest: "/_memc", host: "localhost:3001", referrer: "http://localhost:3001/"

Please add srcache_store_exp in TODO :)

Thanks for nice module! :)

But i would request a new feature - may be you will realize may be anybody
Please add to TODO :)

Sometimes there is a need to setup different $memc_exptime for different locations
But problem is that $memc_exptime defined in location of memc's module subrequest but srcache's locations are in other places. I cannot use 'set' directive - i tested and set variables are not translated in subrequests

May be i should describe two and more sections like '/memc' (with other $memc_exptime values) in your examples and use other these sections for other locations...

But i think the better is using like srcache_store_exp directive like srcache_store_skip for example (this directive for example should setup $memc_exptime for /memc)

But may be is it not possible because /memc is other subrequest?

Thanks

Potential Issue with Range Requests

Response headers for pdf file request -> https://gist.github.com/3239727

basic config for location with srcache:

 #set $key $uri$args;
 #srcache_fetch GET /memc $key;
 #srcache_store PUT /memc $key;
 #srcache_response_cache_control off;

Specifically Google Chrome displays an error, but other browsers appear to intermittently work?

cache files

hey, how can i store a files content from the server ? for example i have some image files on the server and when i request image/file.png it gets on srcache instructions and if it is a miss i wanna store the file's content into the redis key.

thanks

Location header rewritten coming from cache

We're running into an issue where the Location header sent in a 302 request is getting changed depending on if the response is a cache MISS or HIT. On misses, a relative URL is returned (as desired). On hits, an absolute URL is returned despite a relative URL being saved to the cache.

The srcache configuration:

srcache_response_cache_control on;
srcache_default_expire 0s;

set $key $scheme$host$request_uri$bb_accept$requested_with$cookie__bb_locale$cookie__bb_country;
set_escape_uri $escaped_key $key;

srcache_fetch GET /redis $key;
srcache_store PUT /redis2 key=$escaped_key&exptime=$srcache_expire;

When submitting a request that returns 302 response that is a cache MISS, the Location header is relative.

curl -i -H "Host: foobar.example.com" localhost/categories/non-gmo
HTTP/1.1 302 Moved Temporarily
Server: openresty
Date: Thu, 05 Feb 2015 21:03:42 GMT
Content-Type: text/plain; charset=UTF-8
Content-Length: 64
Connection: keep-alive
Vary: X-HTTP-Method-Override, Accept
Cache-Control: public, max-age=3600
Location: /categories/non-gmo-2/products
127.0.0.1 - - [05/Feb/2015:20:59:49 +0000] "GET /categories/non-gmo HTTP/1.1" 302 64 "-" "curl/7.35.0" 0.003 0.001 - - foobar.example.com public, max-age=3600 - MISS

We can see that the response is now cached in our redis instance:

redis-cache:6379> GET foobar.example:938810f609eeeddf722e3ac68ecca339
"HTTP/1.1 302 Moved Temporarily\r\nContent-Type: text/plain; charset=UTF-8\r\nVary: X-HTTP-Method-Override, Accept\r\nCache-Control: public, max-age=3600\r\nLocation: /categories/non-gmo-2/products\r\n\r\nMoved Temporarily. Redirecting to /categories/non-gmo-2/products"

Subsequent requests that generate a cache HIT are returned with a FQDN in the Location header rather than the relative path:

curl -i -H "Host: foobar.example.com" localhost/categories/non-gmo
HTTP/1.1 302 Moved Temporarily
Server: openresty
Date: Thu, 05 Feb 2015 21:08:15 GMT
Content-Type: text/plain; charset=UTF-8
Content-Length: 64
Location: http://foobar.example.com/categories/non-gmo-2/products
Connection: keep-alive
Vary: X-HTTP-Method-Override, Accept
Cache-Control: public, max-age=3600
127.0.0.1 - - [05/Feb/2015:21:08:15 +0000] "GET /categories/non-gmo HTTP/1.1" 302 64 "-" "curl/7.35.0" 0.003 - - - foobar.example.com - - HIT

I've tried using proxy_redirect off; in the nginx configuration, but it doesn't seem to have an affect on the responses coming from srcache.

If I use srcache_store_statuses 200; to explicitly not cache redirect pages, responses include relative Location headers and aren't cached. This is less desirable in our environment, but is a temporary workaround.

Can you confirm that srcache rewriting the Location header being returned in cached responses? Is there an option for disabling the behavior we're experiencing?

Thank you.

Question: Can you include a Redis password/AUTH?

Im using lua-nginx-module as a reverse proxy.

I have a master Redis that the slave reads from - this for speed.

I would much prefer if I could write to the master - Is there a way I can include a AUTH password to the redis connection?

multiple definition of `ngx_http_srcache_filter_module' when compile openresty

Version:openresty-1.11.2.5

config

./configure \
--prefix=/usr/local/openresty \
--sbin-path=/usr/local/openresty/sbin/nginx \
--conf-path=/etc/nginx/nginx.conf \
--error-log-path=/data/logs/error.log \
--http-log-path=/data/logs/access.log \
--pid-path=/var/run/openresty.pid  \
--lock-path=/var/lock/openresty.lock \
--user=nginx \
--group=nginx \
--with-cc-opt=-DTCP_FASTOPEN=23 \
--with-ipv6 \
--with-file-aio \
--with-threads \
--with-http_iconv_module \
--with-http_gzip_static_module \
--with-http_v2_module \
--with-http_ssl_module \
--with-http_realip_module \
--with-http_degradation_module \
--with-http_geoip_module \
--with-stream \
--with-stream_ssl_module \
--with-openssl=./bundle/openssl-1.0.2j \
--with-openssl-opt=-DOPENSSL_THREADS\ -pthread\ -D_REENTRANT\ -D_THREAD_SAFE\ -D_THREADSAFE \
--with-pcre=./bundle/pcre-8.39 \
--add-module=./bundle/srcache-nginx-module-0.31 \
--without-http_redis2_module \
--with-debug

error stack

cc -o objs/nginx \
        objs/src/core/nginx.o \
        objs/src/core/ngx_log.o \
        objs/src/core/ngx_palloc.o \
        objs/src/core/ngx_array.o \
        objs/src/core/ngx_list.o \
        objs/src/core/ngx_hash.o \
        objs/src/core/ngx_buf.o \
        objs/src/core/ngx_queue.o \
        objs/src/core/ngx_output_chain.o \
        objs/src/core/ngx_string.o \
        objs/src/core/ngx_parse.o \
        objs/src/core/ngx_parse_time.o \
        objs/src/core/ngx_inet.o \
        objs/src/core/ngx_file.o \
        objs/src/core/ngx_crc32.o \
        objs/src/core/ngx_murmurhash.o \
        objs/src/core/ngx_md5.o \
        objs/src/core/ngx_sha1.o \
        objs/src/core/ngx_rbtree.o \
        objs/src/core/ngx_radix_tree.o \
        objs/src/core/ngx_slab.o \
        objs/src/core/ngx_times.o \
        objs/src/core/ngx_shmtx.o \
        objs/src/core/ngx_connection.o \
        objs/src/core/ngx_cycle.o \
        objs/src/core/ngx_spinlock.o \
        objs/src/core/ngx_rwlock.o \
        objs/src/core/ngx_cpuinfo.o \
        objs/src/core/ngx_conf_file.o \
        objs/src/core/ngx_module.o \
        objs/src/core/ngx_resolver.o \
        objs/src/core/ngx_open_file_cache.o \
        objs/src/core/ngx_crypt.o \
        objs/src/core/ngx_proxy_protocol.o \
        objs/src/core/ngx_syslog.o \
        objs/src/event/ngx_event.o \
        objs/src/event/ngx_event_timer.o \
        objs/src/event/ngx_event_posted.o \
        objs/src/event/ngx_event_accept.o \
        objs/src/event/ngx_event_connect.o \
        objs/src/event/ngx_event_pipe.o \
        objs/src/os/unix/ngx_time.o \
        objs/src/os/unix/ngx_errno.o \
        objs/src/os/unix/ngx_alloc.o \
        objs/src/os/unix/ngx_files.o \
        objs/src/os/unix/ngx_socket.o \
        objs/src/os/unix/ngx_recv.o \
        objs/src/os/unix/ngx_readv_chain.o \
        objs/src/os/unix/ngx_udp_recv.o \
        objs/src/os/unix/ngx_send.o \
        objs/src/os/unix/ngx_writev_chain.o \
        objs/src/os/unix/ngx_udp_send.o \
        objs/src/os/unix/ngx_channel.o \
        objs/src/os/unix/ngx_shmem.o \
        objs/src/os/unix/ngx_process.o \
        objs/src/os/unix/ngx_daemon.o \
        objs/src/os/unix/ngx_setaffinity.o \
        objs/src/os/unix/ngx_setproctitle.o \
        objs/src/os/unix/ngx_posix_init.o \
        objs/src/os/unix/ngx_user.o \
        objs/src/os/unix/ngx_dlopen.o \
        objs/src/os/unix/ngx_process_cycle.o \
        objs/src/os/unix/ngx_linux_init.o \
        objs/src/event/modules/ngx_epoll_module.o \
        objs/src/os/unix/ngx_linux_sendfile_chain.o \
        objs/src/os/unix/ngx_linux_aio_read.o \
        objs/src/core/ngx_thread_pool.o \
        objs/src/os/unix/ngx_thread_cond.o \
        objs/src/os/unix/ngx_thread_mutex.o \
        objs/src/os/unix/ngx_thread_id.o \
        objs/src/event/ngx_event_openssl.o \
        objs/src/event/ngx_event_openssl_stapling.o \
        objs/src/core/ngx_regex.o \
        objs/src/http/ngx_http.o \
        objs/src/http/ngx_http_core_module.o \
        objs/src/http/ngx_http_special_response.o \
        objs/src/http/ngx_http_request.o \
        objs/src/http/ngx_http_parse.o \
        objs/src/http/modules/ngx_http_log_module.o \
        objs/src/http/ngx_http_request_body.o \
        objs/src/http/ngx_http_variables.o \
        objs/src/http/ngx_http_script.o \
        objs/src/http/ngx_http_upstream.o \
        objs/src/http/ngx_http_upstream_round_robin.o \
        objs/src/http/ngx_http_file_cache.o \
        objs/src/http/ngx_http_write_filter_module.o \
        objs/src/http/ngx_http_header_filter_module.o \
        objs/src/http/modules/ngx_http_chunked_filter_module.o \
        objs/src/http/v2/ngx_http_v2_filter_module.o \
        objs/src/http/modules/ngx_http_range_filter_module.o \
        objs/src/http/modules/ngx_http_gzip_filter_module.o \
        objs/src/http/ngx_http_postpone_filter_module.o \
        objs/src/http/modules/ngx_http_ssi_filter_module.o \
        objs/src/http/modules/ngx_http_charset_filter_module.o \
        objs/src/http/modules/ngx_http_userid_filter_module.o \
        objs/src/http/modules/ngx_http_headers_filter_module.o \
        objs/src/http/ngx_http_copy_filter_module.o \
        objs/src/http/modules/ngx_http_not_modified_filter_module.o \
        objs/src/http/v2/ngx_http_v2.o \
        objs/src/http/v2/ngx_http_v2_table.o \
        objs/src/http/v2/ngx_http_v2_huff_decode.o \
        objs/src/http/v2/ngx_http_v2_huff_encode.o \
        objs/src/http/v2/ngx_http_v2_module.o \
        objs/src/http/modules/ngx_http_static_module.o \
        objs/src/http/modules/ngx_http_gzip_static_module.o \
        objs/src/http/modules/ngx_http_autoindex_module.o \
        objs/src/http/modules/ngx_http_index_module.o \
        objs/src/http/modules/ngx_http_auth_basic_module.o \
        objs/src/http/modules/ngx_http_access_module.o \
        objs/src/http/modules/ngx_http_limit_conn_module.o \
        objs/src/http/modules/ngx_http_limit_req_module.o \
        objs/src/http/modules/ngx_http_realip_module.o \
        objs/src/http/modules/ngx_http_geo_module.o \
        objs/src/http/modules/ngx_http_geoip_module.o \
        objs/src/http/modules/ngx_http_map_module.o \
        objs/src/http/modules/ngx_http_split_clients_module.o \
        objs/src/http/modules/ngx_http_referer_module.o \
        objs/src/http/modules/ngx_http_rewrite_module.o \
        objs/src/http/modules/ngx_http_ssl_module.o \
        objs/src/http/modules/ngx_http_proxy_module.o \
        objs/src/http/modules/ngx_http_fastcgi_module.o \
        objs/src/http/modules/ngx_http_uwsgi_module.o \
        objs/src/http/modules/ngx_http_scgi_module.o \
        objs/src/http/modules/ngx_http_memcached_module.o \
        objs/src/http/modules/ngx_http_empty_gif_module.o \
        objs/src/http/modules/ngx_http_browser_module.o \
        objs/src/http/modules/ngx_http_degradation_module.o \
        objs/src/http/modules/ngx_http_upstream_hash_module.o \
        objs/src/http/modules/ngx_http_upstream_ip_hash_module.o \
        objs/src/http/modules/ngx_http_upstream_least_conn_module.o \
        objs/src/http/modules/ngx_http_upstream_keepalive_module.o \
        objs/src/http/modules/ngx_http_upstream_zone_module.o \
        objs/src/stream/ngx_stream.o \
        objs/src/stream/ngx_stream_variables.o \
        objs/src/stream/ngx_stream_script.o \
        objs/src/stream/ngx_stream_handler.o \
        objs/src/stream/ngx_stream_core_module.o \
        objs/src/stream/ngx_stream_proxy_module.o \
        objs/src/stream/ngx_stream_upstream.o \
        objs/src/stream/ngx_stream_upstream_round_robin.o \
        objs/src/stream/ngx_stream_ssl_module.o \
        objs/src/stream/ngx_stream_limit_conn_module.o \
        objs/src/stream/ngx_stream_access_module.o \
        objs/src/stream/ngx_stream_map_module.o \
        objs/src/stream/ngx_stream_return_module.o \
        objs/src/stream/ngx_stream_upstream_hash_module.o \
        objs/src/stream/ngx_stream_upstream_least_conn_module.o \
        objs/src/stream/ngx_stream_upstream_zone_module.o \
        objs/addon/src/ndk.o \
        objs/addon/src/ngx_http_iconv_module.o \
        objs/addon/src/ngx_http_echo_module.o \
        objs/addon/src/ngx_http_echo_util.o \
        objs/addon/src/ngx_http_echo_timer.o \
        objs/addon/src/ngx_http_echo_var.o \
        objs/addon/src/ngx_http_echo_handler.o \
        objs/addon/src/ngx_http_echo_filter.o \
        objs/addon/src/ngx_http_echo_sleep.o \
        objs/addon/src/ngx_http_echo_location.o \
        objs/addon/src/ngx_http_echo_echo.o \
        objs/addon/src/ngx_http_echo_request_info.o \
        objs/addon/src/ngx_http_echo_subrequest.o \
        objs/addon/src/ngx_http_echo_foreach.o \
        objs/addon/src/ngx_http_xss_filter_module.o \
        objs/addon/src/ngx_http_xss_util.o \
        objs/addon/src/ngx_coolkit_handlers.o \
        objs/addon/src/ngx_coolkit_module.o \
        objs/addon/src/ngx_coolkit_variables.o \
        objs/addon/src/ngx_http_set_base32.o \
        objs/addon/src/ngx_http_set_default_value.o \
        objs/addon/src/ngx_http_set_hashed_upstream.o \
        objs/addon/src/ngx_http_set_quote_sql.o \
        objs/addon/src/ngx_http_set_quote_json.o \
        objs/addon/src/ngx_http_set_unescape_uri.o \
        objs/addon/src/ngx_http_set_misc_module.o \
        objs/addon/src/ngx_http_set_escape_uri.o \
        objs/addon/src/ngx_http_set_hash.o \
        objs/addon/src/ngx_http_set_local_today.o \
        objs/addon/src/ngx_http_set_hex.o \
        objs/addon/src/ngx_http_set_base64.o \
        objs/addon/src/ngx_http_set_random.o \
        objs/addon/src/ngx_http_set_secure_random.o \
        objs/addon/src/ngx_http_set_rotate.o \
        objs/addon/src/ngx_http_set_hmac.o \
        objs/addon/src/ngx_http_form_input_module.o \
        objs/addon/src/ngx_http_encrypted_session_module.o \
        objs/addon/src/ngx_http_encrypted_session_cipher.o \
        objs/addon/src/ngx_http_srcache_filter_module.o \
        objs/addon/src/ngx_http_srcache_util.o \
        objs/addon/src/ngx_http_srcache_var.o \
        objs/addon/src/ngx_http_srcache_store.o \
        objs/addon/src/ngx_http_srcache_fetch.o \
        objs/addon/src/ngx_http_srcache_headers.o \
        objs/addon/src/ngx_http_lua_script.o \
        objs/addon/src/ngx_http_lua_log.o \
        objs/addon/src/ngx_http_lua_subrequest.o \
        objs/addon/src/ngx_http_lua_ndk.o \
        objs/addon/src/ngx_http_lua_control.o \
        objs/addon/src/ngx_http_lua_time.o \
        objs/addon/src/ngx_http_lua_misc.o \
        objs/addon/src/ngx_http_lua_variable.o \
        objs/addon/src/ngx_http_lua_string.o \
        objs/addon/src/ngx_http_lua_output.o \
        objs/addon/src/ngx_http_lua_headers.o \
        objs/addon/src/ngx_http_lua_req_body.o \
        objs/addon/src/ngx_http_lua_uri.o \
        objs/addon/src/ngx_http_lua_args.o \
        objs/addon/src/ngx_http_lua_ctx.o \
        objs/addon/src/ngx_http_lua_regex.o \
        objs/addon/src/ngx_http_lua_module.o \
        objs/addon/src/ngx_http_lua_headers_out.o \
        objs/addon/src/ngx_http_lua_headers_in.o \
        objs/addon/src/ngx_http_lua_directive.o \
        objs/addon/src/ngx_http_lua_consts.o \
        objs/addon/src/ngx_http_lua_exception.o \
        objs/addon/src/ngx_http_lua_util.o \
        objs/addon/src/ngx_http_lua_cache.o \
        objs/addon/src/ngx_http_lua_contentby.o \
        objs/addon/src/ngx_http_lua_rewriteby.o \
        objs/addon/src/ngx_http_lua_accessby.o \
        objs/addon/src/ngx_http_lua_setby.o \
        objs/addon/src/ngx_http_lua_capturefilter.o \
        objs/addon/src/ngx_http_lua_clfactory.o \
        objs/addon/src/ngx_http_lua_pcrefix.o \
        objs/addon/src/ngx_http_lua_headerfilterby.o \
        objs/addon/src/ngx_http_lua_shdict.o \
        objs/addon/src/ngx_http_lua_socket_tcp.o \
        objs/addon/src/ngx_http_lua_api.o \
        objs/addon/src/ngx_http_lua_logby.o \
        objs/addon/src/ngx_http_lua_sleep.o \
        objs/addon/src/ngx_http_lua_semaphore.o \
        objs/addon/src/ngx_http_lua_coroutine.o \
        objs/addon/src/ngx_http_lua_bodyfilterby.o \
        objs/addon/src/ngx_http_lua_initby.o \
        objs/addon/src/ngx_http_lua_initworkerby.o \
        objs/addon/src/ngx_http_lua_socket_udp.o \
        objs/addon/src/ngx_http_lua_req_method.o \
        objs/addon/src/ngx_http_lua_phase.o \
        objs/addon/src/ngx_http_lua_uthread.o \
        objs/addon/src/ngx_http_lua_timer.o \
        objs/addon/src/ngx_http_lua_config.o \
        objs/addon/src/ngx_http_lua_worker.o \
        objs/addon/src/ngx_http_lua_ssl_certby.o \
        objs/addon/src/ngx_http_lua_ssl_ocsp.o \
        objs/addon/src/ngx_http_lua_lex.o \
        objs/addon/src/ngx_http_lua_balancer.o \
        objs/addon/src/ngx_http_lua_ssl_session_storeby.o \
        objs/addon/src/ngx_http_lua_ssl_session_fetchby.o \
        objs/addon/src/ngx_http_lua_ssl.o \
        objs/addon/src/ngx_http_lua_upstream_module.o \
        objs/addon/src/ngx_http_headers_more_filter_module.o \
        objs/addon/src/ngx_http_headers_more_headers_out.o \
        objs/addon/src/ngx_http_headers_more_headers_in.o \
        objs/addon/src/ngx_http_headers_more_util.o \
        objs/addon/src/ngx_http_array_var_module.o \
        objs/addon/src/ngx_http_array_var_util.o \
        objs/addon/src/ngx_http_memc_module.o \
        objs/addon/src/ngx_http_memc_request.o \
        objs/addon/src/ngx_http_memc_response.o \
        objs/addon/src/ngx_http_memc_util.o \
        objs/addon/src/ngx_http_memc_handler.o \
        objs/addon/redis-nginx-module-0.3.7/ngx_http_redis_module.o \
        objs/addon/src/ngx_http_rds_json_filter_module.o \
        objs/addon/src/ngx_http_rds_json_processor.o \
        objs/addon/src/ngx_http_rds_json_util.o \
        objs/addon/src/ngx_http_rds_json_output.o \
        objs/addon/src/ngx_http_rds_json_handler.o \
        objs/addon/src/ngx_http_rds_csv_filter_module.o \
        objs/addon/src/ngx_http_rds_csv_processor.o \
        objs/addon/src/ngx_http_rds_csv_util.o \
        objs/addon/src/ngx_http_rds_csv_output.o \
        objs/addon/src/ngx_http_srcache_filter_module.o \
        objs/addon/src/ngx_http_srcache_util.o \
        objs/addon/src/ngx_http_srcache_var.o \
        objs/addon/src/ngx_http_srcache_store.o \
        objs/addon/src/ngx_http_srcache_fetch.o \
        objs/addon/src/ngx_http_srcache_headers.o \
        objs/ngx_modules.o \
        -L/nas/software/openresty-1.11.2.4/build/luajit-root/usr/local/openresty/luajit/lib -Wl,-rpath,/usr/local/openresty/luajit/lib -Wl,-E -ldl -lpthread -lpthread -lcrypt -L/nas/software/openresty-1.11.2.4/build/luajit-root/usr/local/openresty/luajit/lib -lluajit-5.1 -lm -ldl /nas/software/openresty-1.11.2.4/bundle/pcre-8.39/.libs/libpcre.a /nas/software/openresty-1.11.2.4/bundle/openssl-1.0.2j/.openssl/lib/libssl.a /nas/software/openresty-1.11.2.4/bundle/openssl-1.0.2j/.openssl/lib/libcrypto.a -ldl -lz -lGeoIP \        
-Wl,-E
objs/addon/src/ngx_http_srcache_filter_module.o:(.data+0x0): multiple definition of `ngx_http_srcache_filter_module'
objs/addon/src/ngx_http_srcache_filter_module.o:(.data+0x0): first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_discard_bufs':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:135: multiple definition of `ngx_http_srcache_discard_bufs'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:135: first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_cmp_int':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:1269: multiple definition of `ngx_http_srcache_cmp_int'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:1269: first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_hide_headers_hash':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:1127: multiple definition of `ngx_http_srcache_hide_headers_hash'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:1127: first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_post_request_at_head':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:365: multiple definition of `ngx_http_srcache_post_request_at_head'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:365: first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_store_response_header':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:848: multiple definition of `ngx_http_srcache_store_response_header'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:848: first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_add_copy_chain':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:306: multiple definition of `ngx_http_srcache_add_copy_chain'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:306: first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_process_header':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:697: multiple definition of `ngx_http_srcache_process_header'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:697: first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_process_status_line':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:648: multiple definition of `ngx_http_srcache_process_status_line'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:648: first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_request_no_cache':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:479: multiple definition of `ngx_http_srcache_request_no_cache'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:479: first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_response_no_cache':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:548: multiple definition of `ngx_http_srcache_response_no_cache'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:548: first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_adjust_subrequest':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:255: multiple definition of `ngx_http_srcache_adjust_subrequest'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:255: first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0x0): multiple definition of `ngx_http_srcache_content_length_header_key'
objs/addon/src/ngx_http_srcache_util.o:(.data+0x0): first defined here
objs/addon/src/ngx_http_srcache_util.o: In function `ngx_http_srcache_parse_method_name':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:147: multiple definition of `ngx_http_srcache_parse_method_name'
objs/addon/src/ngx_http_srcache_util.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_util.c:147: first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0xd0): multiple definition of `ngx_http_srcache_propfind_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0xd0): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0xe0): multiple definition of `ngx_http_srcache_proppatch_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0xe0): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0x10): multiple definition of `ngx_http_srcache_get_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0x10): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0x30): multiple definition of `ngx_http_srcache_post_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0x30): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0x80): multiple definition of `ngx_http_srcache_mkcol_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0x80): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0xa0): multiple definition of `ngx_http_srcache_delete_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0xa0): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0xc0): multiple definition of `ngx_http_srcache_options_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0xc0): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0x20): multiple definition of `ngx_http_srcache_put_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0x20): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0xb0): multiple definition of `ngx_http_srcache_unlock_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0xb0): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0x90): multiple definition of `ngx_http_srcache_trace_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0x90): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0x40): multiple definition of `ngx_http_srcache_head_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0x40): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0x50): multiple definition of `ngx_http_srcache_copy_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0x50): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0x60): multiple definition of `ngx_http_srcache_move_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0x60): first defined here
objs/addon/src/ngx_http_srcache_util.o:(.data+0x70): multiple definition of `ngx_http_srcache_lock_method'
objs/addon/src/ngx_http_srcache_util.o:(.data+0x70): first defined here
objs/addon/src/ngx_http_srcache_var.o: In function `ngx_http_srcache_add_variables':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_var.c:164: multiple definition of `ngx_http_srcache_add_variables'
objs/addon/src/ngx_http_srcache_var.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_var.c:164: first defined here
objs/addon/src/ngx_http_srcache_store.o: In function `ngx_http_srcache_filter_init':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_store.c:664: multiple definition of `ngx_http_srcache_filter_init'
objs/addon/src/ngx_http_srcache_store.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_store.c:664: first defined here
objs/addon/src/ngx_http_srcache_fetch.o: In function `ngx_http_srcache_fetch_post_subrequest':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_fetch.c:285: multiple definition of `ngx_http_srcache_fetch_post_subrequest'
objs/addon/src/ngx_http_srcache_fetch.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_fetch.c:285: first defined here
objs/addon/src/ngx_http_srcache_fetch.o: In function `ngx_http_srcache_access_handler':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_fetch.c:26: multiple definition of `ngx_http_srcache_access_handler'
objs/addon/src/ngx_http_srcache_fetch.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_fetch.c:26: first defined here
objs/addon/src/ngx_http_srcache_headers.o: In function `ngx_http_srcache_process_header_line':
/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_headers.c:111: multiple definition of `ngx_http_srcache_process_header_line'
objs/addon/src/ngx_http_srcache_headers.o:/nas/software/openresty-1.11.2.4/bundle/srcache-nginx-module-0.31/src/ngx_http_srcache_headers.c:111: first defined here
objs/addon/src/ngx_http_srcache_headers.o:(.data+0x0): multiple definition of `ngx_http_srcache_headers_in'
objs/addon/src/ngx_http_srcache_headers.o:(.data+0x0): first defined here
collect2: ld returned 1 exit status
gmake[2]: *** [objs/nginx] Error 1
gmake[2]: Leaving directory `/nas/software/openresty-1.11.2.4/build/nginx-1.11.2'
gmake[1]: *** [build] Error 2
gmake[1]: Leaving directory `/nas/software/openresty-1.11.2.4/build/nginx-1.11.2'
gmake: *** [all] Error 2

could not build the variables_hash on 1.4.1

After upgrading from 1.2.9 to 1.4.1 receive this on startup:

[emerg] could not build the variables_hash, you should increase either variables_hash_max_size: 512 or variables_hash_bucket_size: 64

Setting variables_hash_max_size: 1024 fixes the issue, but this wasn't required for 1.2.9

Using tag v0.21

example using srcache with php-fpm

Hi,

We are tying to use srcache with php-fpm . Please advice if you have any reference we can use for our implementation.

Thank you,
Vishal

srcache_store not working with Redis for large files

Hi,
I am running nginx-1.4.5 with the HttpSRCache module and using redis as the backend.

srcache-module version: v0.26
ngx_redis2 version: v0.10
echo-nginx version: v0.50
ngx_set_misc version: v0.24

my nginx.conf (snippet) is:
location / {
set $key $uri;
set_escape_uri $escaped_key $key;

    srcache_fetch GET /redis2-get $key;
    srcache_store PUT /redis2-set key=$escaped_key&exptime=3600;

    proxy_pass http://backend;

}
location = /redis2-get {
internal;

    redis2_query get $arg_key
    redis2_pass <redis_server_ip>:6379;
}

location = /redis2-set {
    internal;

    set_unescape_uri $exptime $arg_exptime;
    set_unescape_uri $key $arg_key;
    set_md5 $key;

    proxy_set_header  Accept-Encoding  "";

    redis2_query set $key $echo_request_body;
    redis2_query expire $key $exptime;
    redis2_pass <redis_server_ip>:6379;
}

I am seeing that when the response is small ( currently I am seeing anything < 1K ), it gets stored on the redis server.

However, when I am fetching a bigger response( currently I am seeing issues with anything > 100K ), everything seems fine, i.e I can see the nginx doing a 'set' on the redis server, but nothing gets stored on the redis.

Is there any size limitation? Can I see any logs to debug this issue? Right now, I see nothing in the nginx or the redis logs.

Is there any known issue? Thanks in advance.
-anirudh

fetch_status / store_status in lua

I am trying to retreive the status of $srcache_fetch_status,$srcache_store_status in lua. No matter which phase I try, the output is always BYPASS,BYPASS ($srcache_fetch_status,$srcache_store_status).

Currently I am trying in log_by_lua since I figured it would be the most likely to have these set, I have also tried content_by_lua in post_action and the rewrite phase.

Is this a bug?

To replicate:

ngx.log(ngx.ERR,ngx.var.srcache_store_status..","..ngx.var.srcache_store_status)

proxy pass blank

I will try and produce exact replication instructions, but the basics of what happened are.

Http Proxy backend, backend is inaccessible due to 100% packet loss, srcache caches an empty page as result (where it should have BYPASS'ed).

I haven't tracked down the cause yet, or loaded this into a VM (once I work out how to replicate it).

Could anything in the configuration cause this behavior (I cant see an options that would)? This was on a production server, so I will have to copy the config off and work backwards.

If-None-Match let cache MISS always

Hi!

If-None-Match has been set cache is miss always.

Test:

curl -I --header "If-None-Match: 23333333" http://xx.xx.fm/api/xxxxx
I think it's a bug or should can be configure.

HTTP/1.1 200 OK
X-Cached-From: MISS
X-Cached-Store: BYPASS

I used srcache-nginx-module-0.30 with openresty 1.9.7.4

this is my config

    location ^~ /api/ {

        add_header X-Cached-From $srcache_fetch_status;
        add_header X-Cached-Store $srcache_store_status;

       set $key $uri;
       set_escape_uri $escaped_key $key;

       set_by_lua $exptime '
           if string.find(ngx.var.uri, "/api/liveshow/rank/") then
               return 300
           end
           return 60
       ';

       srcache_fetch GET /redis $key;
       srcache_store PUT /redis2 key=$escaped_key&exptime=$exptime;

       srcache_methods GET;

       proxy_pass http://127.0.0.1:8881/api/;
   }

thx:)

srcache_fetch stucked while processing some requests

Hello, i get very strange trouble with directive "srcache_fetch" and some kind of SOAP requests.

When i send some POST requests from SOAP UI or another app with User-Agent like "HTTP/Apache (java)" to Openresty, some requests processed well: sending GET request to memc_pass, then store cache, go to proxy_pass and send responds to client.
But other requests are stuck after response from memcached server and wait till client closes connection by it's own timeout (that can be much more than memc_read timeout).

BTW, when i send SOAP request with same body by CURL, i can't reproduce this problem - all requests processed well.

openresty version: 1.11.2.5
nginx version: nginx/1.10.2

This is depersonalized part of my nginx.conf^

	location = /memc {
        internal;
        memc_connect_timeout 100ms;
        memc_send_timeout 100ms;
        memc_read_timeout 100ms;
        memc_ignore_client_abort off;

        set $memc_key $query_string;
        set $memc_exptime 3600;


        memc_pass memcached-ip-addr:memcached-port;
    }

   location /memc-stats {
       add_header Content-Type text/plain;
       set $memc_cmd stats;
       memc_pass memcached-ip-addr:memcached-port;
   }


    location /location-name  {

        access_log logs/access.log main;
        set $responsebody "0";
        set $reqbody "0";
        set $key "0";

        lua_need_request_body on;
        client_max_body_size 50M;

        rewrite_by_lua '

        local method = ngx.var.request_method
        if method == "POST" then
            ngx.req.read_body()
            local data = ngx.req.get_body_data()
            ngx.var.reqbody = data
        elseif method == "GET" then
            local data = ngx.var.query_string
            ngx.var.reqbody = data
        end
        ngx.var.key = ngx.md5(ngx.var.reqbody)
        return ngx.var.key
		';

        srcache_request_cache_control off;
        srcache_response_cache_control off;
        srcache_ignore_content_encoding on;
        srcache_store_private on;

        srcache_fetch GET /memc $key;
        srcache_store_statuses 200 201 301 302;


        srcache_store PUT /memc $key;
        srcache_methods GET POST;


        proxy_pass http://proxy-pass-addr;

 
        proxy_buffering         off;
        proxy_connect_timeout 5s;
        proxy_send_timeout 5s;
        proxy_read_timeout 30s;

    }

srcache 模块执行顺序

你好,我想问一个问题:
srcache_fetch srcache_store proxy_pass(memc_passredis_pass) 在srcache_fetch 命中与不命中情况下的执行顺序。因为我翻看了你的README,还是有疑惑。

Redis cache not working

Hi,

I'm following your exemple of redis caching and I'm not having always MISS as result.
I'm using openresty/1.7.2.1 .

This is my config, I omitted some values of it because they contain our company data.

   location /redis {

        internal  ;
        set_md5  $redis_key $args;
        redis_pass  redis-endpoint.com:6379;

    }
    location /redis2 {

        internal  ;
        set_unescape_uri  $exptime $arg_exptime;
        set_unescape_uri  $key $arg_key;
        set_md5  $key;
        redis2_query  set $key $echo_request_body;
        redis2_query  expire $key $exptime;
        redis2_pass  redis-endpoint.com:6379;

    }
    location ~ ^/ {         
        add_header XXXX;
        proxy_set_header  XXXX;
        set  $key $host$request_uri;
        default_type  text/css;
        srcache_response_cache_control  off;
        srcache_ignore_content_encoding  on;
        set_escape_uri  $escaped_key $key;
        srcache_fetch  GET /redis $key;
        srcache_store  PUT /redis2 key=$escaped_key&exptime=1500;
        proxy_pass  http://upstream;
        proxy_set_header  Host                           $host;
        proxy_read_timeout  300s;
        proxy_set_header  User-Agent                     $http_user_agent;
        proxy_pass_header  Set-Cookie;
        proxy_pass_header  X-Track;
        proxy_pass_header  P3P;
        add_header  Cache-Control no-cache;
        add_header  X-Cache-Status $srcache_fetch_status;
        access_log  /var/log/nginx/access.log access-log;

    }

Intermittently, when I send a request to the "srcached" location, I receive in the error log two messages like these:

2014/08/19 18:36:24 [error] 11188#0: *603 srcache_fetch: cache sent invalid status line while sending to client, client: xx.xx.xx.xx, server: , request: "GET / HTTP/1.1", subrequest: "/redis", upstream: "http://xx.xx.xx.xx:80/redis?www.hostname.com./param=value", host: "www.hostname.com"

2014/08/19 18:36:24 [error] 11188#0: *603 srcache_fetch: cache sent truncated response body while sending to client, client: xx.xx.xx.xx, server: , request: "GET / HTTP/1.1", subrequest: "/redis", upstream: "http://xx.xx.xx.xx:80/redis?www.hostname.com./param=value", host: "www.hostname.com"

Can you help me?

Thanks in advance!

How do you use redis with password?

Hey!

I would really like to use this module but the redis in my environment needs to have authentication turned on.

I tried to solve this by using content_by_lua but don't know how to.

This is what I would want to do but nginx redis or redis2 modules don't support redis passwords:

location /api {
     default_type text/css;

     set $key $uri;
     set_escape_uri $escaped_key $key;

     srcache_fetch GET /redis $key;
     srcache_store PUT /redis2 key=$escaped_key&exptime=120;

     # fastcgi_pass/proxy_pass/drizzle_pass/postgres_pass/echo/etc
 }

 location = /redis {
     internal;

     set_md5 $redis_key $args;
     redis_pass 127.0.0.1:6379;
 }

 location = /redis2 {
     internal;

     set_unescape_uri $exptime $arg_exptime;
     set_unescape_uri $key $arg_key;
     set_md5 $key;

     redis2_query set $key $echo_request_body;
     redis2_query expire $key $exptime;
     redis2_pass 127.0.0.1:6379;
 }

srcache_fetch: $key is not set correctly after access_by_lua subrequest

Hi,

I have the configuration below:

set $mykey test;
access_by_lua 'local res = ngx.location.capture("/my_test") if res.status == 200 then ngx.var.mykey = res.body end';

set $key $mykey;
srcache_fetch GET /memc $key;
srcache_store PUT /memc $key;

Where /my_test sub-request returns test2 with status code 200.

I expect the $key passed to memc to be set to test2, but it is always set to test.

I have read that access_by_lua runs in the end of access, while srcache_fetch runs post-access.

Could you explain this behavior?

P.S. Compliments for your amazing modules!!!

Thanks!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.