# Content Encoding Error while returning data from memcached stored by ngx\_srcache

**URL:** <https://www.ruby-forum.com/t/content-encoding-error-while-returning-data-from-memcached-stored-by-ngx-srcache/217924>\
**Category:** NGINX\
**Created:** [March 16, 2012, 12:59pm UTC](https://www.ruby-forum.com/t/content-encoding-error-while-returning-data-from-memcached-stored-by-ngx-srcache/217924 "2012-03-16T12:59:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![dubstep](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/cdc98d/32.png) [@dubstep](https://www.ruby-forum.com/u/dubstep)\
**Post date:** [March 16, 2012, 12:59pm UTC](https://www.ruby-forum.com/t/content-encoding-error-while-returning-data-from-memcached-stored-by-ngx-srcache/217924/1 "2012-03-16T12:59:25Z")

</div>

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](http://pastebin.com/fUeD2yCA)

Error log when there is data in memcahced  
[http://pastebin.com/Vism9Yyp](http://pastebin.com/Vism9Yyp)

Please advice.

Posted at Nginx Forum:

> **[Content Encoding Error while returning data from memcached stored by ngx\_srcache](https://forum.nginx.org/read.php?2,223951,223951#msg-223951)**
>
> 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...

---

<div class="post-metadata">

**Author:** ![n1xman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@n1xman](https://www.ruby-forum.com/u/n1xman)\
**Post date:** [March 16, 2012, 1:31pm UTC](https://www.ruby-forum.com/t/content-encoding-error-while-returning-data-from-memcached-stored-by-ngx-srcache/217924/2 "2012-03-16T13:31:07Z")

</div>

On Fri, Mar 16, 2012 at 7:58 PM, n1xman [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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 🙂

Best regards,  
-agentzh

---

<div class="post-metadata">

**Author:** ![n1xman](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/13edae/32.png) [@n1xman](https://www.ruby-forum.com/u/n1xman)\
**Post date:** [March 16, 2012, 6:23pm UTC](https://www.ruby-forum.com/t/content-encoding-error-while-returning-data-from-memcached-stored-by-ngx-srcache/217924/3 "2012-03-16T18:23:07Z")

</div>

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:

> **[Re: Content Encoding Error while returning data from memcached stored by...](https://forum.nginx.org/read.php?2,223951,223976#msg-223976)**
>
> 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...
