nginx用expires对页面进行缓存时要配合if_modified,在nginx的一些模块中对http header进行了过滤使得expires无法生效。比如ssi和sub模块,在编译的时候要将这两个模块中的对应过滤http头功能注释。
vim ngx_http_ssi_filter_module.c
......
if (r == r->main) {
vim ngx_http_ssi_filter_module.c
......
if (r == r->main) {
ngx_http_clear_content_length(r);
ngx_http_clear_last_modified(r); 注释这句
ngx_http_clear_accept_ranges(r);
}
......
vim ngx_http_sub_filter_module.c
......
if (r == r->main) {
ngx_http_clear_content_length(r);
ngx_http_clear_last_modified(r); 注释这句
}
......
注释clear_last_modified语句,然后编译nginx
nginx中对global-events-1,global-analyzes-2,global-pulse-3及feature下的文件进行缓存设置
vim nginx.conf
location ~ /(global-events-1|global-analyzes-2|global-pulse-3|feature) {
if ( !-f $request_filename )
{
proxy_pass http://backend_server;
}
expires 30d;
}
ngx_http_clear_last_modified(r); 注释这句
ngx_http_clear_accept_ranges(r);
}
......
vim ngx_http_sub_filter_module.c
......
if (r == r->main) {
ngx_http_clear_content_length(r);
ngx_http_clear_last_modified(r); 注释这句
}
......
注释clear_last_modified语句,然后编译nginx
nginx中对global-events-1,global-analyzes-2,global-pulse-3及feature下的文件进行缓存设置
vim nginx.conf
location ~ /(global-events-1|global-analyzes-2|global-pulse-3|feature) {
if ( !-f $request_filename )
{
proxy_pass http://backend_server;
}
expires 30d;
}
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/27181165/viewspace-775761/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/27181165/viewspace-775761/