背景
記錄一下配置時候的坑,想做到如下的目的。對默認的 index.html 不做任何的處理,只顯示,但對下面的分享文件夾做目錄美化,讓他更好看,

配置如下
server {
listen 80;
listen [::]:80;
server_name localhost;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location /share {
root /usr/share/nginx/html;
index index.html index.htm;
charset utf-8;
autoindex on;
autoindex_exact_size off;
autoindex_localtime on;
autoindex_format html;
add_after_body /autoindex/footer.html;
}
location / {
root /usr/share/nginx/html;
index index.html index.htm;
charset utf-8;
}
}
有兩個 location 那我訪問的時候采用哪一個配置。一句話,采用匹配字符最多的,舉個例子
http://ip:端口/share/ 能匹配到/share, 那么肯定是采用了 location /share 下面的配置,
http://ip:端口/image/ 那就只匹配上了一個/ 自然采用 location / 下面的配置,
http://ip:端口/share/算法書籍 還是采用了 location /share 下面的配置,
http://ip:端口/logo.png 還是只能只匹配上了一個/ 自然采用 location / 下面的配置,
注意:匹配的時候是從端口后面開始匹配的,兩個的是這樣,多個的也類似
