【问题标题】:Nginx Directory Listing only for subpath [duplicate]Nginx 目录列表仅用于子路径 [重复]
【发布时间】:2020-09-08 05:22:22
【问题描述】:

我试图将我的子路径设置为仅在 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;
    }
}

我没有指定/ 部分,是不是上面导致的问题不起作用?我错过了什么?

【问题讨论】:

  • 文件在哪个目录下?
  • @RichardSmith http://file.example.com/test 应该列出/var/www/abc/def/ 中的文件
  • Nginx 正在/var/www/abc/def/test/ 的目录中查找文件。尝试使用alias 而不是root。例如:alias /var/www/abc/def/;

标签: nginx nginx-location nginx-config


【解决方案1】:

将位置更改为location /test

将所有文件复制到/var/www/abc/def/test 文件夹,因为您正在使用位置指令和根指令。在您的情况下,当 Nginx 搜索静态文件时,它将使用根路径 /var/www/abc/def 并附加位置路径 /test

或者按照@RichardSmith 的建议使用别名。

【讨论】:

    猜你喜欢
    • 2015-12-06
    • 2019-03-07
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 2013-07-16
    • 1970-01-01
    • 2016-06-28
    相关资源
    最近更新 更多