51工具盒子

依楼听风雨
笑看云卷云舒,淡观潮起潮落

nginx autoindex 案例

这里一定注意 alias 和root 的区别, 最好用 alias 能方便控制路径

cat autoindex.conf

    server {
        listen      60081;
        server_name baimeidashu.com;
        charset utf-8;
        location / {
                root   /etc;
                autoindex       on;
                autoindex_exact_size    off;
                autoindex_localtime     on;
        }
      location /download {
               alias /var/log/;
               autoindex on; # 开启目录索引功能,可选,用于展示目录内容列表
         }

}

访问:

http://10.0.0.215:60081/download/

是 /var/log 目录

http://10.0.0.215:60081/

是 /etc 的内容

root alias 的区别:

        location  /a {
                alias /data/aaa/;   #完整路径
	 #访问 http://ip/a ,路径为 /data/aaa
	
	
        location  /aaa {
                root /data;   #对上alias,这里不用带上aaa
	  #访问,http://ip/aaa/ ,路径为 /data/aaa
赞(0)
未经允许不得转载:工具盒子 » nginx autoindex 案例