nginx负载memcached不能返回304状态字问题的解决方法
时间:2014-07-05 10:41 来源:linux.it.net.cn 作者:IT网
nginx负载memcached不能返回304状态字问题的解决方法
一、问题描述:
使用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,
在Memcached-1.4.4中memcachd.c中2700行修改为
复制代码代码如下:
time_t t;
time(&t);
flags = t;
if (! (flags
&& safe_strtol(tokens[3].value, &exptime_int)
&& safe_strtol(tokens[4].value, (int32_t *)&vlen))) {
out_string(c, "CLIENT_ERROR bad command line format");
return;
}
(责任编辑:IT)
nginx负载memcached不能返回304状态字问题的解决方法
一、问题描述:
二、问题解决:
--- nginx-0.8.34.orig/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,
在Memcached-1.4.4中memcachd.c中2700行修改为
复制代码代码如下:
time_t t;
if (! (flags (责任编辑:IT) |