【发布时间】: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正在读取的整个配置。