Nginx 忽略子目錄的過期標頭

Nginx 忽略子目錄的過期標頭

我已經在我的伺服器(Fedora 21 x64)上編譯並安裝了 nginx。

我為靜態內容添加了過期時間和一些額外的標頭。但問題是我 nginx 沒有為根目錄和子目錄添加過期和額外的標頭。

讓我解釋清楚。

mydomain.com/anything.html <-- 過期 + 新增了額外標頭。

mydomain.com/index.html -->(重定向)mydomain.com/ <-- 無標頭,不會過期。

mydomain.com/projects/index.html -->(重定向)mydomain.com/projects/ <-- 無標頭,不會過期。

我已將伺服器配置為將 /index.html 重定向到其父子目錄。

這是配置的部分:

if ($request_uri ~ ^(.*/)index\.html($|\?.*)?) {
  return 301 $1$2;
}

location ~* \.html$ {
  expires max;
  add_header "x-ua-compatible" "ie=edge";
  add_header x-frame-options deny;
  add_header x-content-type-options nosniff;
  add_header x-xss-protection "1; mode=block";
  add_header "cache-control" "no-transform";
  access_log logs/static.log;
}

答案1

沒關係。這是一個重新排序的問題。

這是工作配置。

location ~* \.html$ {
    add_header "x-ua-compatible" "ie=edge";
    add_header x-frame-options deny;
    add_header x-content-type-options nosniff;
    add_header x-xss-protection "1; mode=block";
    add_header "cache-control" "no-transform";
    expires max;
    gzip_static always;
    access_log logs/static.log;
}

location ~* \.(?:html|css|js|txt|xml)$ {
  gzip_static always;
}

相關內容