找不到应该根据configuration的vHostfind的PHP文件

我试图用Docker设置一个Symfony 3.x应用程序。 我通过docker-compose.yml文件configuration了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中也没有看到任何条目。

泊坞窗,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 

问题是,用你的定义:

 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; } 

你正在使用返回404的PHP页面。

你应该改变行try_files $uri /app.php$is_args$args;

try_files $uri /app_dev.php$is_args$args;