Nginx打開目錄瀏覽功能(autoindex)
Nginx默認是不允許列出整個目錄的。如需此功能,打開nginx.conf文件或你要啟用目錄瀏覽虛擬主機的配置文件,在server或location 段里添加上autoindex on;來啟用目錄流量,下面會分情況進行說明。
另外Nginx的目錄流量有兩個比較有用的參數,可以根據自己的需求添加:
autoindex_exact_size off;
默認為on,顯示出文件的確切大小,單位是bytes。
改為off后,顯示出文件的大概大小,單位是kB或者MB或者GB
autoindex_localtime on;
默認為off,顯示的文件時間為GMT時間。
改為on后,顯示的文件時間為文件的服務器時間
1、整個虛擬主機開啟目錄流量
在server段添加
location / {
autoindex on;
autoindex_localtime on; #之類的參數寫這里
}
2、單獨目錄開啟目錄流量
2.1:直接二級目錄開啟目錄流量
location /down/ {
autoindex on;
}
2.2:虛擬目錄開啟目錄流量
location /down/ {
alias /home/wwwroot/lnmp/test/;
autoindex on;
}
詳細參照:http://nginx.org/en/docs/http/ngx_http_autoindex_module.html
需要注意root和alias的區別:
alias 設置的目錄是準確的,可以理解為linux的 ln命令創建軟連接,location就是軟連接的名字。如上面2.2例子訪問 http://域名/down/vpser.txt 是直接訪問的/home/wwwroot/lnmp/test/下面的vpser.txt文件。
root 設置的目錄是根目錄,locatoin里所指定名稱的目錄,必須在root設定下的目錄有相同名字的目錄。如果將上面2.2例子里的alias改成root?訪問 http://域名/down/vpser.txt 是直接訪問的的/home/wwwroot/lnmp/test/down/ 目錄下的vpser.txt文件。
需要注意的是alias目錄必須要以 / 結尾且alias只能在location中使用。
如果想希望做出漂亮的目錄列表,支持header,footer則可以安裝三方插件:
http://wiki.nginx.org/NginxNgxFancyIndex
重啟nginx,使其生效。
>>轉載請注明出處:VPS偵探 本文鏈接地址:http://www.0794baidu.com/build/nginx-autoindex.html










@taokai, root /home/wwwroot/default/dl;替換為alias /home/wwwroot/default/dl/;
重啟了還是不行!
user www www;
worker_processes auto;
error_log /home/wwwlogs/nginx_error.log crit;
pid /usr/local/nginx/logs/nginx.pid;
#Specifies the value for maximum file descriptors that can be opened by this process.
worker_rlimit_nofile 51200;
events
{
use epoll;
worker_connections 51200;
multi_accept on;
}
http
{
include mime.types;
default_type application/octet-stream;
server_names_hash_bucket_size 128;
client_header_buffer_size 32k;
large_client_header_buffers 4 32k;
client_max_body_size 50m;
sendfile on;
tcp_nopush on;
keepalive_timeout 60;
tcp_nodelay on;
fastcgi_connect_timeout 300;
fastcgi_send_timeout 300;
fastcgi_read_timeout 300;
fastcgi_buffer_size 64k;
fastcgi_buffers 4 64k;
fastcgi_busy_buffers_size 128k;
fastcgi_temp_file_write_size 256k;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_http_version 1.1;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/javascript text/css application/xml application/xml+rss;
gzip_vary on;
gzip_proxied expired no-cache no-store private auth;
gzip_disable "MSIE [1-6]\.";
#limit_conn_zone $binary_remote_addr zone=perip:10m;
##If enable limit_conn_zone,add "limit_conn perip 10;" to server section.
server_tokens off;
#log format
log_format access '$remote_addr - $remote_user [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" $http_x_forwarded_for';
access_log off;
server
{
listen 81 default_server;
#listen [::]:81 default_server ipv6only=on;
server_name http://www.lnmp.org;
index index.html index.htm index.php;
root /home/wwwroot/default;
location /images {
root /home/wwwroot/default/dl;
autoindex on;
}
#error_page 404 /404.html;
include enable-php.conf;
location /nginx_status
{
stub_status on;
access_log off;
}
location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires 30d;
}
location ~ .*\.(js|css)?$
{
expires 12h;
}
location ~ /\.
{
deny all;
}
access_log /home/wwwlogs/access.log access;
}
include vhost/*.conf;
}
@Dianso, 把你的配置文件發上來看一下
還是沒成功餓