Welcome! Log In Create A New Profile

Advanced

Gzip compression not working with pages served through memcached

April 11, 2012 11:17AM
Hi,

I'm trying to set up nginx so that it serves entire pages from memcached. If it can't find the requested URI in memcached, it proxies the request to Apache (running on port 8080 on the same server). It seems to work so far, the only problem being that gzip compression does not work for pages served through memcached. Also, I'm using Ubuntu 11.

Here are my config files:

-----------------------------
/etc/nginx/nginx.conf

user nginx;
worker_processes 1;

error_log /var/log/nginx/error.log warn;
pid /var/run/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_proxied any;

include /etc/nginx/conf.d/*.conf;
}
-----------------------------

/etc/nginx/conf.d/default.conf

server {
listen 80;
server_name localhost test.mydomain.com;

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

location / {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Accept-Encoding gzip,deflate;

# we never cache post requests
if ($request_method = POST)
{
proxy_pass http://test.mydomain.com:8080;
break;
}

# root /usr/share/nginx/html;
# index index.html index.htm;
default_type "text/html; charset=utf-8";
source_charset utf-8;
charset utf-8;
set $memcached_key $uri;
memcached_pass 127.0.0.1:11211;
error_page 404 @notcached;
}


location @notcached {
internal;
# if the file is not found, forward request to proxy
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://test.mydomain.com:8080;
}

#error_page 404 /404.html;

# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}

# proxy PHP scripts and static images to Apache listening on 127.0.0.1:80
#
location ~ \.(php|css|js|jpeg|jpg|gif|png)$ {
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

proxy_pass http://test.mydomain.com:8080;
}

}
-----------------------------

Thanks in advance for your help!

Regards,
- Jay
Subject Author Posted

Gzip compression not working with pages served through memcached

jaynyc April 11, 2012 11:17AM

Re: Gzip compression not working with pages served through memcached

Maxim Dounin April 11, 2012 05:28PM

Re: Gzip compression not working with pages served through memcached

jaynyc April 12, 2012 11:57AM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 68
Record Number of Users: 6 on February 13, 2018
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready