9. Nginx 目录浏览功能(文件服务器)
server {
listen 80;
server_name localhost;
charset utf-8;
#access_log logs/host.access.log main;
location / {
root html;
#index index.html index.htm; 将 index 注释
autoindex on; # 增加这行
}
.......
}
# 注意:修改完成后也需要将 html 目录下的 index.html 文件修改一个其他的名称,因为 nginx 默认访问 index.html
[root@nginx html]# ll -h
总用量 6.6M
-rw-r--r-- 1 root root 494 6月 5 22:23 50x.html
drwxr-xr-x 2 root root 20 6月 7 12:06 demo
-rw-r--r-- 1 root root 612 6月 7 11:42 index.html.bak
drwxr-xr-x 2 root root 24 6月 6 20:56 ip_ens33
drwxr-xr-x 2 root root 24 6月 6 20:57 ip_ens37
drwxr-xr-x 2 root root 24 6月 6 21:15 port_81
drwxr-xr-x 2 root root 24 6月 6 21:15 port_82
drwxr-xr-x 2 root root 24 6月 6 21:55 test1
drwxr-xr-x 2 root root 24 6月 6 21:55 test2
-rw-r--r-- 1 root root 6.6M 6月 6 22:34 test.html