文章详情

  • 游戏榜单
  • 软件榜单
关闭导航
热搜榜
热门下载
热门标签
php爱好者> php文档>nginx负载memcached不能返回304状态字问题的解决

nginx负载memcached不能返回304状态字问题的解决

时间:2010-04-19  来源:reesun

一、问题描述:     使用nginx作为负载均衡,当访问为图片时到memcached中找,如果未找到运行apache模块将相应文件写入memcached。如果访问图片last-modified为改变,则从本地浏览器的缓存中读取相应文件。     但是,每次访问memcached会吧浏览器传过来的头去掉,这样造成的后果就是不能从本地缓存中读取相应文件。
二、问题解决:     经过大量的google,终于找到一个不错的解决方案——修改ngx_http_memcached_module.c源文件,在该模块中加入相应的Last-Modified头。     具体方案如下(nginx 0.8.34):     修改src/http/modules/ngx_http/memcached_module.c文件。

--- nginx-0.8.34.orig/src/http/modules/ngx_http_memcached_module.c    
+++ nginx-0.7.62.mio/src/http/modules/ngx_http_memcached_module.c    

@@ 353行 @@
 
 /* skip flags */
+ long int lm;
+ time_t ims;
+ lm = strtol(p, NULL, 10);
+ if( r->headers_in.if_modified_since == NULL) {
+     ims = 0;
+ } else {
+     ims = ngx_http_parse_time(r->headers_in.if_modified_since->value.data,
+     r->headers_in.if_modified_since->value.len);
+ }
+ ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,
+ "TIEMPOS: lm=\"%d\" ims=\"%d\"", lm, ims);
+
         while (*p) {
             if (*p++ == ' ') {
                 goto length;


@@ 380行 @@
 
         while (*p && *p++ != CR) { /* void */ }
 
+ r->headers_out.last_modified_time = lm;
         r->headers_out.content_length_n = ngx_atoof(len, p - len - 1);
         if (r->headers_out.content_length_n == -1) {
             ngx_log_error(NGX_LOG_ERR, r->connection->log, 0,


相关阅读 更多 +
排行榜 更多 +
辰域智控app

辰域智控app

系统工具 下载
网医联盟app

网医联盟app

运动健身 下载
汇丰汇选App

汇丰汇选App

金融理财 下载