Ошибка 502 Bad Gateway

fenix_63@mail.ru 10 июня 2020 г. 16:49

Всем привет!
С Docker только недавно работаю, всё вроде бы работало нормально, но в один прекрасный день браузер вывалил мне 502 ошибку: Bad Gateway
Причем административная часть сайта (сайт на Битриксе) работает нормально, а вот публичная - вообще ни в какую.

Вот исходники:

docker-kompose.yml (в корневой папке проекта):

```
version: '3'

services:
nginx:
image: nginx:1.14
ports:
- "${NGINX_HOST}:${NGINX_PORT}:80"
volumes:
- ./:/var/www/html:cached
- ./docker/nginx/nginx.conf:/etc/nginx/nginx.conf
depends_on: [php]
env_file: .env
restart: always

php:
    build:
        context: docker/php
        args:
            TIMEZONE: ${TIMEZONE}
    volumes:
        - ./:/var/www/html:cached
        - ./docker/php/php.ini:/usr/local/etc/php/php.ini:cached
        - ./docker/php/php-fpm.conf:/usr/local/etc/php-fpm.d/99-custom.conf:cached
    user: "${DOCKER_UID}"
    env_file: .env
    restart: always

```

docker-kompose.override.yml (в корне проекта)

```
version: '3'

services:
markup:
build: docker/markup
user: "${DOCKER_UID}"
ports:
- "${MARKUP_PORT}:4000"
volumes:
- ./:/app:cached
command: bash -c "npm install --no-save && bower install && gulp external"
environment:
NODE_ENV: "${MARKUP_ENV}"

.env file (root folder):

COMPOSE_PROJECT_NAME=nrd

"docker-compose.yml:docker-compose.prod.yml" for prod

"docker-compose.yml:docker-compose.stage.yml" for stage

COMPOSE_FILE=

DOCKER_UID=1000
DOCKER_ADDRESS=172.17.0.1

"develop" or "production"

MARKUP_ENV=develop
MARKUP_PORT=4000

0.0.0.0 for external access

NGINX_HOST=127.0.0.1
NGINX_PORT=80

TIMEZONE=Europe/Moscow
```

nginx.conf (папка docker/nginx/):

```
user nginx;
worker_processes auto;

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 off;
error_log /dev/null crit;
client_max_body_size 1024M;
client_header_buffer_size 4k;
large_client_header_buffers 4 8k;

sendfile        on;

keepalive_timeout  65;

map $http_x_forwarded_proto $fastcgi_https {
    default off;
    https on;
}

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}

server {
    root   /var/www/html;
    listen       80;
    server_name  _;

    access_log off;
    error_log /dev/null crit;
    charset utf-8;

    location ~ ^/(\.git|log|docker|\.env) {
        return 404;
    }

    location ~ \.php$ {
        fastcgi_pass   php:9000;
        fastcgi_read_timeout 7200;
        fastcgi_send_timeout 72000;
        fastcgi_buffer_size 32k;
        fastcgi_buffers 16 32k;

        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME   $document_root$fastcgi_script_name;
        fastcgi_param HTTPS $fastcgi_https if_not_empty;
        fastcgi_param REMOTE_ADDR $http_x_forwarded_for;
        include        fastcgi_params;

        if (!-f $request_filename) {
            rewrite  ^(.*)/index.php$  $1/ redirect;
        }
    }

    location / {
        index index.php index.html index.htm;

        if (!-e $request_filename){
            rewrite ^(.*)$ /bitrix/urlrewrite.php last;
        }
    }

    location ~ /\.ht {
        deny all;
    }

    location ~* ^.+\.(xml|html|jpg|jpeg|gif|ttf|eot|swf|svg|png|ico|mp3|css|woff2?|zip|tgz|gz|rar|bz2|doc|xls|exe|pdf|dat|avi|ppt|txt|tar|mid|midi|wav|bmp|rtf|wmv|mpeg|mpg|mp4|m4a|spx|ogx|ogv|oga|webm|weba|ogg|tbz|js)$ {
        expires 30d;
        access_log off;
    }
}

}
```

.Dockerfile (папка docker/php):

```

See https://github.com/docker-library/php/blob/master/7.1/fpm/Dockerfile

FROM php:7.1-fpm
ARG TIMEZONE

RUN apt-get update && apt-get install -y \
openssl \
git \
zlibc \
zlib1g \
zlib1g-dev \
libfreetype6-dev \
libssl-dev \
libjpeg62-turbo-dev \
libmemcached-dev \
libmagickwand-dev \
libmcrypt-dev \
libpng-dev \
libicu-dev \
unzip

Install Composer

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

Set timezone

RUN ln -snf /usr/share/zoneinfo/${TIMEZONE} /etc/localtime && echo ${TIMEZONE} > /etc/timezone
RUN printf '[PHP]\ndate.timezone = "%s"\n', ${TIMEZONE} > /usr/local/etc/php/conf.d/tzone.ini
RUN "date"

Type docker-php-ext-install to see available extensions

RUN docker-php-ext-configure gd --with-freetype-dir=/usr/include/ --with-jpeg-dir=/usr/include/
RUN docker-php-ext-install pdo_mysql gd

Install memcached extension

RUN apt-get update \
&& apt-get install -y libmemcached11 libmemcachedutil2 build-essential libmemcached-dev libz-dev \
&& pecl install memcached \
&& echo extension=memcached.so >> /usr/local/etc/php/conf.d/memcached.ini \
&& apt-get remove -y build-essential libmemcached-dev libz-dev \
&& apt-get autoremove -y \
&& apt-get clean \
&& rm -rf /tmp/pear

RUN docker-php-ext-install intl
RUN docker-php-ext-install opcache
RUN docker-php-ext-install soap

RUN apt-get install -y --no-install-recommends default-libmysqlclient-dev

RUN apt-get install -y \
libzip-dev \
zip \
&& docker-php-ext-configure zip --with-libzip \
&& docker-php-ext-install zip

RUN docker-php-ext-install mysqli

WORKDIR /var/www/html

CMD ["php-fpm"]
```

php.ini (папка docker/php):

```
[PHP]
short_open_tag = On
upload_max_filesize = 200M
post_max_size = 250M
display_errors = Off
memory_limit = 1024M
max_execution_time = 60

[mbstring]
mbstring.internal_encoding = UTF-8
mbstring.func_overload = 2
```

php-fpm.conf (папка docker/php):

```
[www]
pm = dynamic
pm.max_children = 50
pm.start_servers = 2
pm.min_spare_servers = 2
pm.max_spare_servers = 10
access.format = "%{REMOTE_ADDR}e - %u %t \"%m %{REQUEST_URI}e%Q%q\" %s %{miliseconds}dms %{megabytes}MM %C%%"
;slowlog = /proc/self/fd/2
;request_slowlog_timeout = 2s

php_admin_value[error_log] = /proc/self/fd/2
php_admin_flag[log_errors] = on
```

.Dockerfile (папка docker/markup):

```
FROM node:10.13

RUN npm install -g gulp bower
RUN echo '{ "allow_root": true }' > /root/.bowerrc

RUN mkdir /.npm && mkdir /.config && mkdir /.cache && mkdir /.local && chmod 777 /.npm && chmod 777 /.config && chmod 777 /.cache && chmod 777 /.local

EXPOSE 4000

WORKDIR /app/markup
```

Помогите пожалуйста, не понимаю в чём дело. Настройки нигде не менял.
Использую Docker for Windows.