最近研究nginx+memcached.
Nginx配置如下
user nobody nobody; worker_processes 1; error_log /usr/local/nginx/nginx_error.log crit; pid /usr/local/nginx/sbin/nginx.pid; events { use epoll; worker_connections 5120; } http { #include mime.types; # default_type text/html; # sendfile on; # tcp_nodelay on; # upstream memcached { # server 127.0.0.1:22345 weight=4 max_fails=2 fail_timeout=30s; # } # upstream webserver { #server 172.16.20.2:80; # } server { listen 80; server_name localhost; location / { default_type text/html; set $memcached_key $request_uri; memcached_pass 127.0.0.1:22345; error_page 404 = @nodata; } location @nodata { internal; proxy_pass http://XXX.XXX.0.245; break;} } }
是在程序内用memcached客户端存入memcached.
但是在用nginx读取的时候发现所有页面均出现乱码.经多次测试发现页面大小超过16K时就会出现乱码.查询memcached的相关文档得知,是由于memcached客户端内部的一个压缩机制,在页面超过16K时,会自动压缩页面存入memcached.如果用memcached客户