關於nginx的last-modified及強制打開last-modified的方法

nginx如果打開了SSI模塊,會默認關閉header中的last-modified輸出,可以通過修改源代碼來重新打開:
註釋掉src/http/modules/ngx_http_ssi_filter_module.c第362行:

static ngx_int_t
ngx_http_ssi_header_filter(ngx_http_request_t *r)
{


……
if (r == r->main) {
ngx_http_clear_content_length(r);
/*ngx_http_clear_last_modified(r);*/
ngx_http_clear_accept_ranges(r);
}

……
}


如果編譯並使用了--with-http_sub_module模塊,還需要註釋掉src/http/modules/ngx_http_sub_filter_module.c第159行:

static ngx_int_t
ngx_http_sub_header_filter(ngx_http_request_t *r)
{

……
if (r == r->main) {
ngx_http_clear_content_length(r);
/*ngx_http_clear_last_modified(r);*/
}

……

}

注掉源碼,重新編譯就可以了,如果header裏面沒有顯式輸出last-modified,那默認使用的時間是文件的MTIME,要注意。


經過測試,發現上面的方法是可行的,這樣在用ssi的同時也可以讓瀏覽器緩存生效了。


發佈了27 篇原創文章 · 獲贊 3 · 訪問量 13萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章