【问题标题】:directory index of /var/www/html forbidden/var/www/html 的目录索引被禁止
【发布时间】:2020-11-26 17:26:34
【问题描述】:

我正在使用在/etc/nginx/conf.d/default.conf复制的以下文件

server {
    listen 80;
    root /var/www/html/public;
    index index.php index.htm index.html;

    location / {
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        fastcgi_param DOCUMENT_ROOT $realpath_root;

        fastcgi_index index.php;
        fastcgi_pass 127.0.0.1:9000;
    }

    location ~ \.php$ {
        return 404;
    }
}

它在日志中给了我以下错误

*“/var/www/html/”的7个目录索引被禁止,客户端:172.17.0.1,服务器:_,请求:“GET / HTTP/1.1”,主机:“localhost:8080”

尝试调试但没有任何线索。

我的文件在www-data:www-data

如果相关,我正在使用来自 php:7.4-fpm 的 docker 映像。

FROM php:7.4-fpm

WORKDIR /var/www/html

RUN export DEBIAN_FRONTEND=noninteractive

RUN apt-get update && apt-get install -y nginx procps

COPY infrastructure/nginx/default.conf /etc/nginx/conf.d/default.conf

COPY infrastructure/entrypoint.sh /etc/entrypoint.sh

EXPOSE 80

ENTRYPOINT ["sh", "/etc/entrypoint.sh"]

感谢您的帮助。

【问题讨论】:

  • 你是如何运行镜像的?如果你的容器应该运行 Nginx,你为什么要基于 PHP-FPM 镜像?
  • 因为我想避免调整 PHP,而是采用基本默认映像并安装和配置所有扩展。
  • @DavidMaze 这就是我运行容器的方式docker run -p 8080:80 -v /path/to/project:/var/www/html test-php
  • 您发布的ls -al 是从您的主机还是在您的容器内完成的?
  • 错误信息表示/var/www/html中没有index.html文件。您问题中的配置文件将根设置为/var/www/html/public,这意味着它不是 Nginx 使用的配置。使用nginx -T(大写T)查看Nginx正在读取的整个配置。

标签: docker nginx


【解决方案1】:

它说“目录索引......被禁止”不是没有权限。如果您要提供其中一个文件的 URL,例如http://example.com/composer.json ,nginx 应该很乐意将内容返回到您的浏览器。如果您明确想浏览目录中的文件,那么这个must be explicitly enabled in the nginx config

【讨论】:

    猜你喜欢
    • 2017-10-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-05-30
    • 2013-09-03
    • 2019-03-03
    • 1970-01-01
    • 2018-10-16
    相关资源
    最近更新 更多