Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

srcache_fetch subrequest return 405 error code. #34

Closed
chrisLeeTW opened this issue Feb 13, 2015 · 4 comments
Closed

srcache_fetch subrequest return 405 error code. #34

chrisLeeTW opened this issue Feb 13, 2015 · 4 comments

Comments

@chrisLeeTW
Copy link

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.

@chrisLeeTW
Copy link
Author

sorry, my os is CentOS 6.6 64bit
here is my nginx version

nginx version: nginx/1.6.2
built by gcc 4.4.7 20120313 (Red Hat 4.4.7-11) (GCC) 
TLS SNI support enabled
configure arguments: --prefix=/opt/nginx/1.6.2 --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 --user=www-data --group=www-data --with-http_ssl_module --with-http_realip_module --with-http_addition_module --with-http_sub_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_stub_status_module --with-file-aio --with-http_spdy_module --without-select_module --without-poll_module --without-http_ssi_module --without-http_autoindex_module --without-http_uwsgi_module --without-http_scgi_module --without-http_uwsgi_module --without-http_fastcgi_module --without-http_memcached_module --with-cc-opt='-O2 -g -pipe -Wp,-D_FORTIFY_SOURCE=2 -fexceptions -fstack-protector --param=ssp-buffer-size=4 -m64 -mtune=generic' --with-ld-opt=-ljemalloc --with-libatomic --add-module=/root/nginx/nginx_module/nginx-http-sysguard --add-module=/root/nginx/nginx_module/redis2-nginx-module-0.11 --add-module=/root/nginx/nginx_module/srcache-nginx-module-0.28 --add-module=/root/nginx/nginx_module/lua-nginx-module-0.9.14 --add-module=/root/nginx/nginx_module/memc-nginx-module-0.15 --add-module=/root/nginx/nginx_module/ngx_devel_kit-0.2.19 --add-module=/root/nginx/nginx_module/set-misc-nginx-module-0.28 --add-module=/root/nginx/nginx_module/echo-nginx-module-0.57 --add-module=/root/nginx/nginx_module/ngx_http_redis-0.3.7 --with-debug

@agentzh
Copy link
Member

agentzh commented Feb 15, 2015

@chrisLeeTW "if is evil". Please avoid using the "if" directive in your configuration. See

http://wiki.nginx.org/IfIsEvil

@agentzh
Copy link
Member

agentzh commented Feb 15, 2015

@chrisLeeTW Also, the ngx_redis module does not expect a POST method request so you'd better avoid using the POST method in srcache_fetch. That should explain why you're getting the 405 error code.

@chrisLeeTW
Copy link
Author

Thanks for your advice. I check the ngx_redis source code, And it did not allow the post method.

Sorry for the bother.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants