Nginx實戰(六) 引數優化

樑桂釗發表於2016-10-18

Nginx實戰系列目錄

本機快取設定

瀏覽器快取是為了提高載入速度,因此我們可以通過Nginx對靜態檔案進行快取。

location ~ ^/(images|javascript|js|css|flash|media|static)/ {
    #過期30天
    expires 30d;
}

定義錯誤提示頁面

error_page   500 502 503 504  /50x.html;
        location = /50x.html {
        root   html;
}

自動顯示目錄

location / {
    autoindex on;
}

此外,還可以新增兩個引數

  • autoindex_exact_size off; 預設為on,顯示出檔案的確切大小,單位是bytes。改為off後,顯示出檔案的大概大小,單位是kB或者MB或者GB
  • autoindex_localtime on; 預設為off,顯示的檔案時間為GMT時間,改為on後,顯示的檔案時間為檔案的伺服器時間

相關文章