带有 PHP 的 Nginx 的 Docker 机器每隔几个请求就会崩溃

带有 PHP 的 Nginx 的 Docker 机器每隔几个请求就会崩溃

我有一个装有 PHP 和 Nginx 的 docker。
部署的代码不依赖于外部服务。
每 5 分钟(50-100 个请求)我都会收到一个错误(见下图),并且 PHP + Nginx 会重新启动。

2019/12/18 08:52:19 [error] 14#14: *7 connect() failed (111: Connection refused) while connecting to upstream, client: 169.254.8.129, server: , request: "GET /api/getContent?token=90eaf18d505039f3a92e1db026b457&lang=en&populate_module=2 HTTP/1.1", upstream: "fastcgi://127.0.0.1:9000", host: "cms.example.com", referrer: "https://example.com/about"

这是非常随机的。除了下图中看到的内容之外,日志上没有其他内容。

这是docker文件:

FROM php:7.2-fpm
COPY build /var/www/cockpit
COPY startup.sh /var/www/
RUN  apt-get update && apt-get install -y nginx vim
RUN apt-get update && apt-get install -y \
        libfreetype6-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
        libjpeg62-turbo-dev \
        libpng-dev \
        zlib1g-dev \
        lynx \
        iputils-ping \
        vim \
        nginx \
  && rm -rf /var/lib/apt/lists/* \
  && docker-php-ext-configure gd --with-jpeg-dir=/usr/include/ \
  && docker-php-ext-install -j$(nproc) gd \
  && docker-php-ext-install exif \
  && docker-php-ext-install zip \
  && cd ~ \
  && curl -sS https://getcomposer.org/installer -o composer-setup.php  \
  && php composer-setup.php --install-dir=/usr/local/bin --filename=composer \
  && cd /var/www/cockpit \
  && composer global require hirak/prestissimo \
  && composer install \
  && chmod -R 0777 /var/www
  COPY default.conf /etc/nginx/sites-enabled/default 

  CMD ["nginx", "-g", "daemon off;"]
  ENTRYPOINT [ "/var/www/startup.sh" ]

这是startup.sh:

#!/bin/bash
service nginx start
php-fpm

这是 Nginx 配置:

server {
    listen 8080;

    index index.php index.html;
    root /var/www/cockpit;

    # enable gzip compression
    gzip on;
    gzip_min_length  1100;
    gzip_buffers  4 32k;
    gzip_types    text/plain application/x-javascript text/xml text/css image/svg+xml;
    gzip_vary on;
    # end gzip configuration

    # enable browser caching
    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff)$ {
        expires 1y;
        log_not_found off;
    }

    location = /favicon.ico { access_log off; log_not_found off; }
    location = /robots.txt  { access_log off; log_not_found off; }

    # deny direct access to files
    location ~ .sqlite$ {
        deny all;
    }
    location ~ .yaml$ {
        deny all;
    }
    location ~ /\.git {
      deny all;
    }
    location /content {
        rewrite ^/content/(.*)\.(html|md)$ /error redirect;
    }
    # end deny configuration

    location /cockpit {
        try_files $uri $uri/ /cockpit/index.php$is_args$args;
        index index.php index.html index.htm;
    }

    location / {
        try_files $uri $uri/ /index.php$is_args$args;
        index index.php index.html index.htm;
    }

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

    location ~ .sqlite$ {
        deny all;
    }
}

在此处输入图片描述

相关内容