首頁  >  文章  >  運維  >  nginx開啟列目錄的範例分析

nginx開啟列目錄的範例分析

WBOY
WBOY轉載
2023-05-26 11:36:401336瀏覽

nginx開啟列目錄

當你想讓nginx作為檔案下載伺服器存在時,需要開啟nginx列目錄

server {
 location download {
  autoindex on;

  autoindex_exact_size off;
  autoindex_localtime on;
 }
}

autoindex_exact_size: 為on (預設)時顯示檔案的確切大小,單位是byte;改為off顯示檔案大概大小,單位KB或MB或GB

autoindex_localtime: 為off(預設)時顯示的檔案時間為GMT時間;改為on後,顯示的檔案時間為伺服器時間

預設當存取列出的txt等檔案時會在瀏覽器上顯示檔案的內容,如果你想讓瀏覽器直接下載,加上下邊的配置

if ($request_filename ~* ^.*?\.(txt|pdf|jpg|png)$) {
 add_header Content-Disposition 'attachment';
}

以上是nginx開啟列目錄的範例分析的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文轉載於:yisu.com。如有侵權,請聯絡admin@php.cn刪除