For some reason I cannot get the srcache module to work well with HttpRedis2Module module on a redis cluster. srcache works well with HttpRedisModule and HttpRedis2Module on a single redis node (the HttpRedisModule doesn't work with a redis cluster using set_hashed_upstream, sadly)
I am using OpenResty 1.2.7.1 and Redis 2.6.11. I am trying to cache my backend server JSON responses.
daemon off;
pid {{scratch_directory}}/nginx.pid;
error_log {{scratch_directory}}/nginx_error.log;
events {
worker_connections 1024;
}
http {
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
upstream api_server {
}
upstream redis_tesla {
keepalive 512;
}
upstream redis_leaf {
keepalive 512;
}
upstream_list redis_cluster redis_tesla redis_leaf;
proxy_read_timeout 120;
proxy_connect_timeout 120;
server {
listen 9090;
client_max_body_size 10M;
server_name api.*;
access_log {{scratch_directory}}/api_access.log;
error_log {{scratch_directory}}/api_error.log;
location / {
if ($request_method !~ ^(GET|HEAD)$ ) {
return 405;
}
proxy_redirect off;
# Send appropriate headers through
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $http_host;
rewrite ^/api/dev/(.*)$ /$1 break;
# set expiration headers for site calls to be short
expires +120s;
# Only cache valid HTTP responses
srcache_store_statuses 200 301 302;
# only allow pull methods
srcache_methods GET HEAD;
set $key $request_method$request_uri;
set_escape_uri $escaped_key $key;
srcache_fetch GET /redis-get key=$escaped_key;
srcache_store PUT /redis-set key=$escaped_key&exptime=300;
}
location = /redis-get {
internal;
set_unescape_uri $key $arg_key;
redis2_query get $key;
set_hashed_upstream $backend redis_cluster $key;
redis2_pass $backend;
}
location = /redis-set {
internal;
set_unescape_uri $exptime $arg_exptime;
set_unescape_uri $key $arg_key;
set_hashed_upstream $backend redis_cluster $key;
redis2_query set $key $echo_request_body;
redis2_query expire $key $exptime;
redis2_pass $backend;
}
# block common, unnecessary requests
location /favicon.ico {
access_log off;
error_log off;
log_not_found off;
deny all;
}
location /robots.txt {
access_log off;
error_log off;
log_not_found off;
deny all;
}
}
}
Any help would be greatly appreciated.