Docker NGINX + PHP-FPM 502错误网关

时间:2018-11-02 16:41:45

标签: php docker nginx

当我更改php-fpm端口时,我得到了502 Bad Gateway。

我的docker配置:

services:
    service_nginx:
        image: nginx:1.13
        depends_on:
          - service_phpfpm
        volumes:
          - ./nginx/symfony.conf:/etc/nginx/conf.d/symfony.conf
        ports:
          - "8001:8001"
        links:
            - service_phpfpm
        networks:
          default:
            aliases:
              - api.dev.mysite.com
    service_phpfpm:
        build: ./php7-fpm
        ports:
            - 9005:9000
        entrypoint: /var/www/mysite/etc/docker/php7-fpm/run.sh

symfony.conf

server {
  listen   8001;
  server_name api.dev.mysite.com;
  set_real_ip_from 127.0.0.1/32;
  real_ip_header HTTP_X_FORWARDED_FOR;
  root /var/www/mysite/public;

  charset utf-8;
  access_log  /proc/self/fd/1   main;
  error_log  /proc/self/fd/2;

  gzip on;
  gzip_static on;
  gzip_types       text/plain text/javascript text/css application/x-javascript;

  if ($request_uri = '/heathcheck') {
    set $variable         "heathcheck";
  }

  location / {
      try_files $uri @rewriteapp;
  }

  location @rewriteapp {
      rewrite ^(.*)$ /index.php/$1 last;
  }

  location ~ ^/(index|app|app_dev|config)\.php(/|$) {
      fastcgi_pass service_phpfpm:9005;
      fastcgi_split_path_info ^(.+\.php)(/.*)$;
      include fastcgi_params;
      fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
      fastcgi_param HTTPS off;
  }
}

php dockerfile

FROM php:7.1-fpm

# Set timezone
RUN rm /etc/localtime && \
    ln -s /usr/share/zoneinfo/Europe/Paris /etc/localtime && \
    date

# PHP deps
RUN apt-get update -qq && \
    apt-get install -y -qq --no-install-recommends \
        git \
        libxml2-dev \
        libzip-dev \
        unzip \
        && \
    rm -Rf /var/lib/apt/lists/* && \
    # Type docker-php-ext-install to see available extensions
    docker-php-ext-install \
        pdo \
        pdo_mysql \
        soap \
        zip \
        bcmath \
        mbstring \
        sockets

RUN apt-get update -qq && \
    apt-get install -y -qq --no-install-recommends \
    ssh-client

RUN echo 'alias sf="php /var/www/mysite/bin/console"' >> ~/.bashrc

RUN curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer

WORKDIR /var/www/mysite

run.sh

#!/bin/sh
set -e

exec php-fpm

控制台输出:

  

service_phpfpm_1 | [02-Nov-2018 17:24:40]注意:fpm正在运行,pid   1 service_phpfpm_1 | [02-Nov-2018 17:24:40]注意:准备处理   连接

当我尝试访问api时,会得到:

  

service_nginx_1 | 2018/11/02 16:26:06 [错误] 9#9:* 2 connect()   连接到上游客户端时失败(111:连接被拒绝):   172.19.0.4,服务器:api.dev.mysite.com,请求:“ GET / HTTP / 1.1”,上游:“ fastcgi://172.19.0.3:9005”,主机:“ api.dev.mysite.com:8001” “

更改端口的原因是因为我在端口80和9000中运行了另一个nginx + php-fpm。

0 个答案:

没有答案