首页 > 解决方案 > 带有 PHP-FPM 的容器 nginx 不执行 PHP 文件

问题描述

我正在尝试按照教程(http://geekyplatypus.com/dockerise-your-php-application-with-nginx-and-php7-fpm/)使用 PHP-FPM 运行 Nginx,但我在 docker 中运行的 nginx 不解释 PHP文件并返回“403”错误。

我的“site.conf”

server {
index index.php index.html;
server_name learn-wordpress.com;
error_log  /var/log/nginx/error.log;
access_log /var/log/nginx/access.log;
root /usr/share/nginx/html;

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass php:9000;
    fastcgi_index index.php;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_param PATH_INFO $fastcgi_path_info;
}

}

我的“docker-compose.yml”

version: "3"
services:
  web:
    image: nginx:latest
    ports:
      - "80:80"
    container_name: 'wp'
    volumes:
      - "./:/usr/share/nginx/html"
      - ./site.conf:/etc/nginx/conf.d/site.conf
  php:
    image: 'php:7.4-fpm'
    volumes:
      - "./:/var/www/html"

我的 PHP 应用程序是 Wordpress,没有任何更改。

标签: phpwordpressdockernginx

解决方案


推荐阅读