Nginx正在下载index.php而不是执行- Docker + symfony + php-fpm

jhdbpxl9  于 2022-12-02  发布在  PHP
关注(0)|答案(1)|浏览(172)

当我访问“localhost:8000”时,我得到一个403禁止。但是,如果我去“localhost:8000/index.php”,文件正在下载。
我知道有很多这样的问题在那里,但我发誓我已经检查了像50我没有一个这些解决方案似乎对我工作,或者也许我做错了什么...我是完全新的Docker,要有耐心:)
我怀疑这个问题与nginx的配置有关,或者可能是php-fpm服务不工作或无法与nginx服务通信。
以下是相关文件:
php.conf(nginx配置文件):

server {
    listen 80;
    root /public;

    location / {
        # try to serve file directly, fallback to index.php
        try_files $uri /index.php$is_args$args;
    }

    location ~ ^/index\.php(/|$) {
        fastcgi_pass php:9000;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        include fastcgi_params;
        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
        internal;
    }

    location ~ \.php$ {
        return 404;
    }

    error_log /var/log/nginx/project_error.log;
    access_log /var/log/nginx/project_access.log;
}

docker-compose.yml:

version: "3.4"

services:
  php:
    build:
      context: .
      target: app_php
      args:
        SYMFONY_VERSION: ${SYMFONY_VERSION:-}
        STABILITY: ${STABILITY:-stable}
    restart: unless-stopped
    volumes:
      - php_socket:/var/run/php
    healthcheck:
      interval: 10s
      timeout: 3s
      retries: 3
      start_period: 30s

  webserver:
    image: nginx:latest
    ports:
        - 8000:80
    volumes:
        - ./nginx/conf.d/php.conf:/etc/nginx/conf.d/php.conf
        - ./public:/usr/share/nginx/html
    depends_on:
      - php

  mysql:
      image: mysql:8.0
      environment:
          - MYSQL_USER=root
          - MYSQL_ROOT_PASSWORD=admin
          - MYSQL_DATABASE=db
      volumes:
          - symfony-data:/var/lib/mysql

volumes:
  php_socket:
  symfony-data:
###> symfony/mercure-bundle ###
###< symfony/mercure-bundle ###

###> doctrine/doctrine-bundle ###
  db-data:
###< doctrine/doctrine-bundle ###

我的项目文件夹:

  • 资产
  • 组态
  • Docker
  • 文档
  • 移转
  • 恩金
  • 确认日期
  • php.conf
  • 节点模块
  • 公开的
  • 建筑物
  • index.php(这是我正在下载的文件,该死的你,只要运行pls)
  • 源代码
  • 主计长
  • 实体名称
  • 资料档案库
  • 模板
  • 变量
  • 高速缓存
  • 日志. . .
  • 停靠文件
  • docker-compose.yml

任何帮助都将不胜感激。感谢每一个人!!
我在nginx和fpm的配置文件以及docker-composer文件中尝试了很多更改,但没有任何效果...

pgvzfuti

pgvzfuti1#

添加行索引index.php index.html;在nginx配置文件中

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

location / {
    # try to serve file directly, fallback to index.php
    try_files $uri /index.php$is_args$args;
}

location ~ ^/index\.php(/|$) {
    fastcgi_pass php:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;
    fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
    fastcgi_buffer_size 128k;
    fastcgi_buffers 4 256k;
    fastcgi_busy_buffers_size 256k;
    internal;
}

location ~ \.php$ {
    return 404;
}

error_log /var/log/nginx/project_error.log;
access_log /var/log/nginx/project_access.log;

}

相关问题