找不到Docker-compose Nginx php-fpm文件 [英] Docker-compose Nginx php-fpm file not found

查看:125
本文介绍了找不到Docker-compose Nginx php-fpm文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用php-fpm和nginx的简单docker-compose配置,但看不到任何php文件.当我转到本地主机时,它显示找不到文件".

I have a simple docker-compose config with php-fpm and nginx, and I can't see any php file. When I go to localhost, it shows File Not Found.

我尝试了可以​​在网上找到的所有内容,但是尝试的所有内容均失败了. 它适用于html,但不适用于php文件.似乎是路径问题或类似的问题.

I tried everything I could find on the net, but everything I have tried has failed. It works fine for html, but not for php files. Seems to be a path issue, or something like that.

当我docker-compose logs时遇到此错误:

project3-php_1     | 172.17.0.5 -  29/Mar/2016:13:29:12 +0000 "GET /index.php" 404
project3-front_1   | 172.17.0.1 - - [29/Mar/2016:13:29:12 +0000] "GET / HTTP/1.1" 404 27 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/48.0.2564.116 Safari/537.36"
project3-front_1   | 2016/03/29 13:29:12 [error] 8#8: *3 FastCGI sent in stderr: "Primary script unknown" while reading response header from upstream, client: 172.17.0.1, server: localhost, request: "GET / HTTP/1.1", upstream: "fastcgi://172.17.0.2:9000", host: "localhost"

这是我的docker-compose:

Here's my docker-compose:

project3-front:
    image: nginx
    ports:
      - "80:80"
    links:
      - "project3-php:project3-php"
    volumes:
      - ".:/home/docker"
      - "./nginxdir/default.conf:/etc/nginx/conf.d/default.conf"
      - "./html:/usr/share/nginx/html"

  project3-php:
      build: phpdir
      volumes:
        - ".:/home/docker:rw"
        - "./html:/var/www/html"
      ports:
        - "9000:9000"
      working_dir: "/home/docker"

然后将我的dockerfile用于php:

Then my dockerfile for php:

FROM php:5.6-fpm
EXPOSE 9000

我的nginx default.conf:

my default.conf for nginx:

server {
  listen 80;
  server_name localhost;
  index index.php index.html;

  error_log  /var/log/nginx/error.log  warn;
  access_log /var/log/nginx/access.log;
  root /usr/share/nginx/html;

  location ~ \.php$ {
      fastcgi_pass project3-php:9000;
      fastcgi_index index.php;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  }
}

主文件夹的密码是:

/media/revenge/share/PROJECTS/docker_images/php7-nginx

文件层次结构为:

├── docker-compose.yml
├── html
│   ├── index.php
├── nginxdir
│   ├── default.conf
├── phpdir
│   ├── dockerfile
│   └── php.ini

整个文件夹是chmod 777

The whole folder is chmod 777

任何想法将不胜感激.我确定有些东西我没有得到.预先感谢.

Any idea would be greatly appreciated. I'm sure there is something I didn't get. Thanks in advance.

推荐答案

在这里您可以找到问题的方式

  1. 使用自定义command开启nginx调试模式,例如:
  1. Switch on the nginx debug mode with custom command, eg:

docker-compose.yml

docker-compose.yml

web:
    image: nginx
    volumes:
        - "~/www/project:/var/www"
        - "~/www/project/vhost.conf:/etc/nginx/conf.d/site.conf"
    # Add this row:
    command: [nginx-debug, '-g', 'daemon off;']

  1. 编辑您的"site.conf"文件(在本示例中为~/www/project/vhost.conf文件),通过error_log开启调试模式(在末尾添加"debug"一词):
  1. Edit your "site.conf" file (in this example it is the ~/www/project/vhost.conf file) Switch on the debug mode by the error_log (add "debug" word at the end):

error_log "/var/log/nginx/error.log" debug;

  1. (重新)启动网络"容器:

docker-compose stop web
docker-compose up -d web

  1. 测试容器,所有容器都在运行吗?

docker-compose ps

  1. 在浏览器中测试
  2. 连接"并查看或下载( http://blog.dcycle .com/blog/ae67284c/docker-compose-cp )并查看/var/log/nginx/error.log文件.
  1. Test in browser
  2. "Connect" and view or download ( http://blog.dcycle.com/blog/ae67284c/docker-compose-cp ) and view the /var/log/nginx/error.log file.

大多数情况下的问题

您尚未设置,或者您在webphp-fpm中使用了不同的目录结构.如果要使用与必须在fastcgi_param SCRIPT_FILENAME位置设置"fpm结构"不同的结构,如下所示:

The problem in the most of case

You haven't set yet or you are using different directory structure in web and php-fpm. If you want to use different structure than you have to set the "fpm structure" at the fastcgi_param SCRIPT_FILENAME place, like this:

如果您的docker-compose.yml包含以下内容:

If your docker-compose.yml contains like this:

phpfpm:
    image: php:fpm
    volumes:
        - "~/www/project:/var/www/html/user/project"
#                        ^^^^^^^^^^^^^^^^^^^^^^^^^^ the path in the php-fpm container

您必须在nginx容器的"site.conf"中进行设置:

You have to set this in "site.conf" in nginx container:

fastcgi_param SCRIPT_FILENAME /var/www/html/user/project$fastcgi_script_name;
#                             ^^^^^^^^^^^^^^^^^^^^^^^^^^

这篇关于找不到Docker-compose Nginx php-fpm文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆