Nginx Web Server – 列出目錄

在 Web Server 的目錄中,通常會使用 index.html / index.php 等來當做預設打開的檔案,如果目錄中沒有這一類的檔案,就會無法瀏覽目錄中的檔案,這樣可以保護可能因設定不當而造成的資料外洩。

但有時候,目錄中的檔案為了方便使用者下載,所以需要將目錄列出來
[@more@]在 Nginx Web Server 的設定方式
# vim /etc/nginx/nginx.conf
/usr/share/nginx/www/download 目錄為例
http { 段落中加入
        location /download {
                root /usr/share/nginx;
                index index.html index.htm;
                autoindex on;
        }

重新啟動 Nginx Web Server
# /etc/init.d/nginx restart