Content Encoding Error while returning data from memcached stored by ngx_srcache

I need little help here. First time browsing or memcached restart will
show you the data correctly; but when you refresh second time and it
will gives you content encoding error and I think it is something to do
with my nginx or ngx_srcache config for fetching data from memcached. I
checked using Wireshark from the client-end and found nginx sending
uncompressed data and I can see the Accept-encoding and
Connection-encoding on request and response header are set respectively.
I suspect the error triggers due to browser expect compressed data
instead of uncompressed data.

Backend I get uncompressed data and I assume that ngx_srcache will
compress said data before storing them on memcached. If ngx_srcache
compress data and store them in memcached by default, how do we pass
client accept encoding to memcached via ngx_srcache which is not
happening. If I use gzip off; then I get data properly.

Here are my configurations:

uname -a
Linux abmx-test 2.6.18-194.el5PAE #1 SMP Tue Mar 16 22:00:21 EDT 2010
i686 i686 i386 GNU/Linux

./nginx -V
nginx version: nginx/1.1.17
built by gcc 4.1.2 20080704 (Red Hat 4.1.2-48)
TLS SNI support disabled
configure arguments: --add-module=./contrib/echo-nginx-module-6c1f553
–add-module=./contrib/memc-nginx-module-4007350
–add-module=./contrib/simpl-ngx_devel_kit-24202b4
–add-module=./contrib/set-misc-nginx-module-e6a54ab
–add-module=./contrib/srcache-nginx-module-86e7a18 --with-debug
–with-http_ssl_module --with-http_realip_module
–with-http_addition_module --with-http_sub_module
–with-http_dav_module --with-http_mp4_module
–with-http_gzip_static_module --with-http_random_index_module
–with-http_secure_link_module --with-http_stub_status_module
–without-mail_pop3_module --without-mail_imap_module
–without-mail_smtp_module --with-mail_ssl_module

nginx.conf
user nginx;
worker_processes 1;

error_log /usr/local/nginx/logs/error.log debug;
pid /usr/local/nginx/logs/nginx.pid;

events {
worker_connections 1024;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format  main  '$remote_addr - $remote_user [$time_local]

“$request” ’
'$status $body_bytes_sent “$http_referer” ’
‘“$http_user_agent” “$http_x_forwarded_for”’;

access_log  /var/log/nginx/access.log  main;

sendfile        on;
#tcp_nopush     on;

keepalive_timeout  65;

gzip on;
gzip_static on;
gzip_buffers 16 8k;
gzip_proxied any;
gzip_comp_level 8;
gzip_http_version 1.1;
gzip_min_length 512;
gzip_types text/plain text/css application/json
application/x-javascript application/xml application/xml+rss
text/javascript application/javascript text/x-js
application/x-shockwave-flash text/json;
gzip_vary on;

upstream my_mem {
server 127.0.0.1:11211;
}

server {
listen 80;
server_name localhost;

access_log /var/log/nginx/access.log main;
error_log /var/log/nginx/error.log debug;

    default_type application/json;

location = /memc {
internal;

    memc_connect_timeout 100ms;
    memc_send_timeout 100ms;
    memc_read_timeout 100ms;

    set $memc_key $query_string;
    set $memc_exptime 30;
 #   set $memc_exptime $arg_exptime;

    memc_pass my_mem;
}

location /mix2 {
    default_type  "application/json;charset=UTF-8";
    set $key $args;
    srcache_fetch GET /memc key=$key;
    srcache_store PUT /memc key=$key;
    srcache_store_statuses 200 301 302 404;
    srcache_response_cache_control off;

No data found in memcached

 proxy_pass http://192.168.20.101;
 proxy_set_header Accept-Encoding "";

    }

location / {
    root   /usr/share/nginx/html;
    index  index.html index.htm;
}

#
error_page   500 502 503 504  /50x.html;
location = /50x.html {
    root   /usr/share/nginx/html;
}

}
}

Error log when there is not data in memcached
http://pastebin.com/fUeD2yCA

Error log when there is data in memcahced
http://pastebin.com/Vism9Yyp

Please advice.

Posted at Nginx Forum:

On Fri, Mar 16, 2012 at 7:58 PM, n1xman [email protected] wrote:

It looks like a bug in old versions of ngx_srcache (like the one,
v0.13rc2, that you’re currently using). Please try the latest version,
v0.13rc6:

https://github.com/agentzh/srcache-nginx-module/tags

Please let me if the problem still persist with the latest version :slight_smile:

Best regards,
-agentzh

Hi agentzh,

Thanks for the quick response. I have recompiled with the latest
ngx_srcache and now it is working without any error. Thanks again for
the support and this is brilliant piece of module for nginx and we
loving it.

n1xman

Posted at Nginx Forum: