gpt4 book ai didi

php - 找不到PHP文件,应根据配置的vHost找到

转载 作者:行者123 更新时间:2023-12-02 18:31:50 24 4
gpt4 key购买 nike

我正在尝试使用Docker设置Symfony 3.x应用程序。
我通过docker-compose.yml文件配置了3个Docker容器:

  • Nginx
  • Php-fpm
  • MySQL

  • 当我导航到my-project.dev:8080/时,我看到一个简单的404-Not found-页面。
  • 我无法加载my-project.dev:8080/app_dev.php或my-project.dev:8080/config.php(我收到“找不到文件”错误)

  • 我也没有在/var/log/nginx/access.log中看到任何条目。

    docker-compose.yml:
    web:
    image: nginx:latest
    ports:
    - "8080:80"
    volumes:
    - .:/var/www
    - ./docker/vhost.conf:/etc/nginx/sites-enabled/vhost.conf
    - ./docker/nginx.conf:/etc/nginx/nginx.conf
    links:
    - php

    php:
    image: php:5.6-fpm
    volumes:
    - .:/var/www
    links:
    - db

    db:
    image: mysql:latest
    volumes:
    - /var/lib/mysql
    environment:
    - MYSQL_ROOT_PASSWORD=my-password

    nginx.conf文件:
    user  www-data;
    worker_processes 4;

    error_log /var/log/nginx/error.log warn;
    pid /var/run/nginx.pid;

    events {
    worker_connections 1024;
    }

    http {
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
    '$status $body_bytes_sent "$http_referer" '
    '"$http_user_agent" "$http_x_forwarded_for"';

    access_log /var/log/nginx/access.log main;

    sendfile on;
    #tcp_nopush on;

    keepalive_timeout 65;

    #gzip on;

    include /etc/nginx/conf.d/*.conf;
    include /etc/nginx/sites-enabled/*;
    }

    vhost.conf文件:
    server {
    listen *:80;

    server_name my-project.dev;
    root /var/www/web;

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

    # DEV
    # This rule should only be placed on your development environment
    # In production, don't include this and don't deploy app_dev.php or config.php
    location ~ ^/(app_dev|config)\.php(/|$) {
    fastcgi_pass php:9000;
    fastcgi_split_path_info ^(.+\.php)(/.*)$;
    include fastcgi_params;

    fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
    fastcgi_param DOCUMENT_ROOT $realpath_root;
    }

    location ~ \.php$ {
    return 404;
    }

    error_log /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    }

    最佳答案

    我必须通过创建如下图像来覆盖php-fpm图像的WORKDIR:

    Dockerfile:

    FROM php:5.6-fpm
    MAINTAINER Firstname Lastname <firstname.lastname@domain.com>
    WORKDIR /var/www

    构建镜像:
    docker build -t companyx/php-5.6-fpm .

    更新docker-compose文件:
    web:
    image: nginx:latest
    ports:
    - "8080:80"
    volumes:
    - .:/var/www
    - ./docker/vhost.conf:/etc/nginx/sites-enabled/vhost.conf
    - ./docker/nginx.conf:/etc/nginx/nginx.conf
    links:
    - php

    php:
    image: companyx/php-5.6-fpm
    volumes:
    - .:/var/www
    links:
    - db

    db:
    image: mysql:latest
    volumes:
    - /var/lib/mysql
    environment:
    - MYSQL_ROOT_PASSWORD=my-password

    关于php - 找不到PHP文件,应根据配置的vHost找到,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40948024/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com