Nginx 1.5.x 版本啟用 nginx-http-concat 模組後,合併請求返回 400 Bad Request,1.4.x 正常。
Nginx 1.5+ 標準化 JS MIME 類型為 application/javascript,但模組源碼 ngx_http_concat_module.c 僅識別舊類型 application/x-javascript,導致類型匹配失敗,拒絕處理請求。
文件:nginx-http-concat-master/ngx_http_concat_module.c 第 14 行左右
// 原代碼
static ngx_str_t ngx_http_concat_default_types[] = {
ngx_string("application/x-javascript"),
ngx_string("text/css"),
ngx_null_string
};
static ngx_str_t ngx_http_concat_default_types[] = {
ngx_string("application/javascript"),
ngx_string("text/css"),
ngx_null_string
};
static ngx_str_t ngx_http_concat_default_types[] = {
ngx_string("application/x-javascript"),
ngx_string("application/javascript"),
ngx_string("text/css"),
ngx_null_string
};
./configure --prefix=/usr/local/nginx --add-module=../nginx-http-concat-master
make && make install
/usr/local/nginx/sbin/nginx -s reload
合併請求 /static/js/a.js??b.js 正常返回 200,響應頭 Content-Type: application/javascript。
text/css 穩定無需變更