I'm using memcached to store html content ready for nginx to display but I'm getting the compressed output in the browser.

It works if I turn off compression in PHP but doubles the response time which is the key part here so ideally I'd like to keep the compression on and decompress in nginx.

Any suggestions?

Here is the conf;

worker_processes  1;

events {
    worker_connections  1024;

http {

    include /usr/local/nginx/conf/mime.types;
    server {
        listen 80;
        server_name mydomain.com;
        access_log /path/to/access/log/access_log;
        error_log /path/to/error/log/error_log;
        root /default/path/to/files;

        location ~* \.(jpg|png|gif|css|js|swf|flv|ico|html|woff|ttf|svg|htm)$ {
                try_files $uri $uri/ $uri.html @notcached;

        location ~* \.php$ {
                fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
                fastcgi_read_timeout 240;
                include fastcgi_params;

        location / {
                default_type text/html;
                set $enhanced_memcached_key "$server_name$request_uri";
                enhanced_memcached_hash_keys_with_md5 on;
                enhanced_memcached_pass memcache.local:11211;
                error_page 404 = @notcached;

        location @notcached {
                fastcgi_param SCRIPT_FILENAME /u1/live/sites/public_html/index.html;
                fastcgi_param PATH_INFO $fastcgi_script_name;
                fastcgi_read_timeout 240;
                include fastcgi_params;

  • so where does the compression happen? does PHP compress the html before storing inside the memcache? what kind of compression is that? if its normal gzip, maybe you don't need to uncompress in Nginx, but just add the right headers, so the browser can decompress it for yout.
    – replay
    Feb 18 '13 at 12:38
  • Hi, I believe it's the default compression in Memcached which is apparently zlib compression. It can be turned off in PHP but as the response time trebles from displaying the compressed data and displaying the html uncompressed I'd prefer to try and decompress it first.
    – glambert
    Feb 18 '13 at 13:05

Have you tried this? if it matches your compression algorithm, then this should help you: http://openhack.ru/nginx-patched/wiki/MemcachedGzip

  • Hi, I did try to use this but I don't think, unless I'm mistaken, it will work when using the enhanced_memcached module, which is required so that we can use MD5s as the memcached keys.
    – glambert
    Feb 18 '13 at 14:09

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.