首页 > 解决方案 > ngnix 上的目录列表

问题描述

嗨,我正在尝试使用 ngnix 上的目录列表功能列出一组 pdf。

这些文件位于 /files

我的dockerfile如下

FROM nginx
WORKDIR /files
COPY pdfs /files/

COPY conf.d/default.conf /etc/nginx/conf.d/
EXPOSE 4200 80

ENTRYPOINT ["nginx", "-g", "daemon off;"]

default.conf 已修改

server {
    listen       80;
    server_name  localhost;

    #charset koi8-r;
    #access_log  /var/log/nginx/host.access.log  main;

    location / {
        root   /usr/share/nginx/html;
        index  index.html index.htm;
    }

    location /files {
        root /files;
        autoindex on;
    }
    #error_page  404              /404.html;

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }
}

但是当我点击 http://localhost/files 时,我得到了

404 未找到 nginx/1.19.4

标签: nginxnginx-location

解决方案


/some/path当您在 a 下声明根时,将在目录下搜索location /uri/prefix { ... }通过请求的任何文件。检查和nginx 指令之间的区别。您可以使用指令,也可以尝试使用(我想知道它是否会起作用,但对我来说应该)。/uri/prefix/file/some/path/uri/prefixrootaliasalias /files;root "";


推荐阅读