Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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;
        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;

share|improve this question
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. – mauro.stettler 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:

share|improve this answer
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 posting your answer, you agree to the privacy policy and terms of service.

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