在nginx中不像apache默認是打開目錄瀏覽功能的,在nignx中目錄瀏覽功能默認是關閉了,下面我來介紹在nginx中實現目錄瀏覽功能的配置方法。
打開nginx.conf文件,在location server 或 http段中加入
1
|
autoindex on; |
另外兩個參數最好也加上去:
1
|
autoindex_exact_size off; |
默認為on,顯示出文件的確切大小,單位是bytes。
改為off后,顯示出文件的大概大小,單位是kB或者MB或者GB
autoindex_localtime on;
默認為off,顯示的文件時間為GMT時間。
改為on后,顯示的文件時間為文件的服務器時間
1
2
3
4
|
location /{ root /var/www/html; autoindex on; } |
這段代碼的意思就是把 /var/www/html目錄作為根目錄來直接列出來。
如果我們想只顯示一個網站或一個目錄,其實很簡單,把該網站的.conf文件全部修改才行。如修改成如下即可:
1
2
3
4
5
6
7
8
9
10
11
12
|
server { listen 80; charset utf-8; server_name localhost; root /www/web/default; location / { autoindex on; autoindex_exact_size off; autoindex_localtime on; } } |