参考网站:http://www.jdon.com/39179
因为项目中的静态资源(HTML,JS,JPG)比较多, 多心考虑台面用nginx搭载memcache增加访问量. 其中nginx.conf中配置(节选如下):
upstream memcached {
server localhost:11211;
}
server {
listen 4444;
server_name localhost;
location / { #这里面上线时会配置成静态资源
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect off;
charset utf-8;
set $memcached_key $uri;
memcached_pass memcached;
error_page 500 404 405 = @fallback;
}
location @fallback {
root /Users/crystal/www/html;
}
|
访问http://localhost:4444/a/b/c/static.html资源的时候,后台日志出现
key: "/a/b/c/static.html" was not found by memcached while reading response header from upstream, client: 127.0.0.1, server: localhost, request: "GET /webpro/img/b.html HTTP/1.1", upstream: "memcached://127.0.0.1:11211", host: "localhost:4444". |
但我用JAVA的客户端从memcache中读取key为/a/b/c/static.html的值是可以准备提取到对应的资源的, 不知为什么nginx就是读不出来. 后来将
set $memcached_key $uri; #改成 set $memcached_key 'fixed_key'; #固定的值,不用$uri |
立即可以显示正确的页面, 另外发现如果key中包含有'/', 那nginx也不能正常读出.
请问, 大家碰到过这种问题没有.
PS: 对C不熟悉, 读nginx的源码有点费劲. ----------------------------

讨论了如何在项目中使用nginx搭配memcache来提高静态资源的访问速度,解决了memcache读取问题,并提供了proxy_cache模块的解决方案。
4881

被折叠的 条评论
为什么被折叠?



