Nginx 反向代理容器返回错误 404 Not Found on .php files

Nginx 反向代理容器返回错误 404 Not Found on .php files

我有一个 nginx 反向代理容器,还有一个 nginx 和一个 php-fpm 容器。我可以毫无问题地提供 .html 文件,但是当我尝试导航到 .php 时,我收到错误 404 Not Found。

这是nginx反向代理的docker-compose.yml:

version: "2"

services:
  nginx-proxy:
    image: jwilder/nginx-proxy:alpine
    container_name: nginx-proxy
    ports:
      - "8080:80"
    volumes:
      - /var/run/docker.sock:/tmp/docker.sock:ro
      - ./vhost.d:/etc/nginx/vhost.d

networks:
  default:
    external:
      name: nginx-proxy-net

这是我的网站的 docker-compose.yml:

version: "2"

services:
  nginx:
    image: nginx:latest
    expose:
      - 80
    restart: always
    volumes:
      - ./html:/usr/share/nginx/html
    environment:
      - VIRTUAL_HOST=vhost.example.it
    container_name: vhost-html

  php:
    image: php:7-fpm
    expose:
      - 9000
    restart: always
    volumes:
      - ./html:/usr/share/nginx/html
    environment:
      - VIRTUAL_PROTO=fastcgi
      - VIRTUAL_ROOT=/usr/share/nginx/html
      - VIRTUAL_PORT=9000
      - VIRTUAL_HOST=vhost-php.local
    container_name: vhost-php

networks:
  default:
    external:
      name: nginx-proxy-net

另外,我在 vhost.d 文件夹中创建了一个每个 VIRTUAL_HOST 的配置文件:

location ~ \.php$ {
    try_files $uri =404;
    fastcgi_split_path_info ^(.+\.php)(/.+)$;
    fastcgi_pass vhost-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;
}

您知道如何修复此错误吗?

相关内容