Nginx和php-fpm docker撰写

时间:2016-09-19 18:57:18

标签: php nginx docker-compose

我正在尝试使用Docker-compose为PHP项目创建开发环境。

我刚创建了一个docker-compose文件,其中包含3个docker:

  • 应用程序:安装我的代码卷
  • Php:运行php5-fpm
  • Nginx:运行nginx Web服务器。

我可以通过我的网络服务器获取一个html文件但是当我尝试使用php文件时,我收到了502 Bad Request错误。

error.log中:

2016/09/19 16:51:18 [error] 8#0: *2 connect() failed (111: Connection refused) while connecting to upstream, client: 172.17.0.1, server: xxx, request: "GET /index.php HTTP/1.1", upstream: "fastcgi://172.17.0.3:9000", host: "xxx"

我认为nginx无法连接到php。

这是我的 docker-compose 文件:

# import the code and bind it on /var/www
application:
  build: code
  volumes:
    - ./sites:/var/www/
  tty: true

# php container
php:
  build: php-fpm
  volumes_from:
    - application
  expose:
    - 9000:9000
  volumes:
    - ./logs/php5-fpm/:/var/log

# nginx container
nginx:
  build: nginx
  ports:
    - 80:80
  links:
    - php
  volumes_from:
    - application
  volumes:
    - ./logs/nginx:/var/log/nginx

PHP-FPM / Dockerfile:

FROM debian:jessie

RUN apt-get update && apt-get install -y php5-common php5-cli php5-fpm php5-mcrypt php5-mysql php5-gd php5-imagick php5-curl php5-intl php5-memcache php5-imap

RUN usermod -u 1000 www-data

CMD ["php5-fpm", "-F"]

EXPOSE 9000

的nginx / Dockerfile:

FROM debian:jessie

RUN apt-get update && apt-get install -y nginx

ADD nginx.conf /etc/nginx
ADD test.conf /etc/nginx/sites-available/

RUN ln -s /etc/nginx/sites-available/test.conf /etc/nginx/sites-enabled/test.conf
RUN rm /etc/nginx/sites-enabled/default

RUN echo "upstream php-upstream { server php:9000; }" > /etc/nginx/conf.d/upstream.conf

RUN usermod -u 1000 www-data

CMD ["nginx"]

EXPOSE 80

的nginx / nginx.conf:

user www-data;
worker_processes 4;
pid /run/nginx.pid;

events {
  worker_connections  2048;
  multi_accept on;
  use epoll;
}

http {
  sendfile on;
  tcp_nopush on;
  tcp_nodelay on;
  keepalive_timeout 65;
  types_hash_max_size 2048;

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

  access_log off;
  error_log off;

  gzip on;
  gzip_disable "msie6";

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

daemon off;

的nginx / test.conf:

server {
  listen 80;

  server_name xxx;
  root /var/www/test;

  location ~ \.php$ {
        fastcgi_pass   php:9000;
        fastcgi_index  index.php;
        fastcgi_split_path_info ^(.+\.php)(/.*)$;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include fastcgi_params;
    }

  error_log /var/log/nginx/test_error.log;
  access_log /var/log/nginx/test_access.log;
}

启动docker-compose时没有错误。

有人可以帮助我吗?

由于

0 个答案:

没有答案
相关问题