我试图使我的子路径仅在Nginx中成为目录列表,但是它返回404。
假设我具有http://file.example.com/test
的以下配置:
server {
listen 80;
server_name file.example.com;
location /test/ {
root /var/www/abc/def/;
autoindex on;
autoindex_exact_size off;
autoindex_format html;
autoindex_localtime on;
}
}
我未指定/
部分,是否是上述问题导致的无效?我错过了什么?
将位置更改为location /test
将所有文件复制到/var/www/abc/def/test
文件夹,因为您将位置指令与根指令一起使用。对于您的情况,当Nginx搜索静态文件时,它将使用根路径/var/www/abc/def
并附加位置路径/test
。
或使用别名,如@RichardSmith建议。