# Nginx + memcached + gzip

**URL:** <https://www.ruby-forum.com/t/nginx-memcached-gzip/231892>\
**Category:** NGINX\
**Created:** [September 4, 2014, 4:39pm UTC](https://www.ruby-forum.com/t/nginx-memcached-gzip/231892 "2014-09-04T16:39:30Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![addis\_a](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/c4cdca/32.png) [@addis\_a](https://www.ruby-forum.com/u/addis_a)\
**Post date:** [September 4, 2014, 4:39pm UTC](https://www.ruby-forum.com/t/nginx-memcached-gzip/231892/1 "2014-09-04T16:39:30Z")

</div>

Hello.

I have service with memcached for storing large xml data. Data is  
compressed  
in memcached. I want to send responce gzipped if client supports that  
and  
decompressed if not. But with my config responce goes to client always  
decompressed. There is my site config:

server {  
listen 80;  
server\_name static.app1.feeds.lan;

```
location / {
    memcached_pass 10.10.0.11:11211;
    gunzip on;
    memcached_gzip_flag 2;
    gzip_static on;
    gzip on;
    gzip_proxied any;
    gzip_types "text/xml";
    gzip_vary on;

    set $memcached_key "null";
    if ($uri ~* "/uploads/(.*)/feed.xml") {
        set $memcached_key $1;
    }
}

```

}

and nginx config:

user www-data;  
worker\_processes 4;  
pid /run/nginx.pid;

events {  
worker\_connections 16384;  
# multi\_accept on;  
}

http {

```
    ##
    # Basic Settings
    ##

    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    # server_tokens off;

    # server_names_hash_bucket_size 64;
    # server_name_in_redirect off;

    include /etc/nginx/mime.types;
    default_type application/octet-stream;
    ##
    # Logging Settings
    ##

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

    ##
    # Gzip Settings
    ##

    gzip on;
    gzip_disable "msie6";

    gzip_vary on;
    gzip_proxied any;
    gzip_types text/plain text/css application/json

```

application/x-javascript text/xml application/xml application/xml+rss  
text/javascript;  
…

Thanks!

Posted at Nginx Forum:

> **[nginx + memcached + gzip](https://forum.nginx.org/read.php?2,253074,253074#msg-253074)**
>
> Hello. I have service with memcached for storing large xml data. Data is compressed in memcached. I want to send responce gzipped if client supports that and decompressed if not. But with my config responce goes to client always decompressed. There...

---

<div class="post-metadata">

**Author:** ![LinU777](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/l/3d9bf3/32.png) [@LinU777](https://www.ruby-forum.com/u/LinU777)\
**Post date:** [September 4, 2014, 4:43pm UTC](https://www.ruby-forum.com/t/nginx-memcached-gzip/231892/2 "2014-09-04T16:43:09Z")

</div>

I have checked with curl:

curl -I [http://static.app1.feeds.lan/uploads/one\_feed/1/feed.xml](http://static.app1.feeds.lan/uploads/one_feed/1/feed.xml)  
–compressed

HTTP/1.1 200 OK  
Server: nginx/1.6.1  
Date: Thu, 04 Sep 2014 14:39:54 GMT  
Content-Type: text/xml  
Connection: keep-alive  
Vary: Accept-Encoding

curl -I [http://static.app1.feeds.lan/uploads/one\_feed/1/feed.xml](http://static.app1.feeds.lan/uploads/one_feed/1/feed.xml)

HTTP/1.1 200 OK  
Server: nginx/1.6.1  
Date: Thu, 04 Sep 2014 14:39:59 GMT  
Content-Type: text/xml  
Connection: keep-alive  
Vary: Accept-Encoding

Posted at Nginx Forum:

> **[Re: nginx + memcached + gzip](https://forum.nginx.org/read.php?2,253074,253075#msg-253075)**
>
> Hello. I have service with memcached for storing large xml data. Data is compressed in memcached. I want to send responce gzipped if client supports that and decompressed if not. But with my config responce goes to client always decompressed. There...
