【问题标题】:Docker environment with nginx and worker_processes带有 nginx 和 worker_processes 的 Docker 环境
【发布时间】:2021-06-03 15:35:32
【问题描述】:

我正在尝试将 worker_processes 添加到我的 docker 环境中的 nginx.conf 文件中,但是每当我尝试时,它都无法重新启动或加载。我相信我在这里遗漏了一些关键概念——无论如何:

这是我的 nginx.conf 文件(一切正常):

server {
    listen 80;
    index index.php index.html;
    error_log  /var/log/nginx/error.log;
    access_log /var/log/nginx/access.log;
    root /var/www/src;

    location ~ \.php$ {
        try_files $uri =404;
        fastcgi_split_path_info ^(.+\.php)(/.+)$;
        fastcgi_pass app: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 / {
        try_files $uri $uri/ /index.php?$query_string;
        gzip_static on;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico)$ {
        expires max;
        log_not_found off;
    }

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

    location = /robots.txt {
        allow all;
        log_not_found off;
        access_log off;
    }

    location ~ ^/wp-json/ {
        rewrite ^/wp-json/(.*?)$ /?rest_route=/$1 last;
    }
}

我尝试在服务器方括号下方添加以下内容,但这会导致 nginx 无法加载。 enginx 的错误是: "worker_processes" 指令在 /etc/nginx/conf.d/nginx.conf:1 中是不允许的 :

worker_processes: 8;

    server {
        listen 80;
        index index.php index.html;
        etc. etc. etc.

这是我的文件夹结构:

这是我目前的 Dockerfile:

FROM php:7.4.15-fpm

# Arguments defined in docker-compose.yml
ARG user
ARG uid

# Install system dependencies
RUN apt-get update && apt-get install -y \
    git \
    curl \
    libpng-dev \
    libonig-dev \
    libxml2-dev \
    zip \
    unzip

# Clear cache
RUN apt-get clean && rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install mysqli pdo_mysql mbstring exif pcntl bcmath g
# Set working directory
WORKDIR /var/www

USER $user

【问题讨论】:

标签: php docker nginx configuration


【解决方案1】:

您位于/etc/nginx/conf.d/nginx.conf 的配置很可能由默认配置文件/etc/nginx/nginx.conf 导入,并带有include /etc/nginx/conf.d/*.conf; 语句。

因此,您的配置位于 http 上下文中,这不允许 worker_processes 指令。您需要编辑应该已经在/etc/nginx/nginx.conf 中定义的现有语句,默认情况下它应该设置为worker_processes auto;

注意:不需要冒号,因此只需将其更改为worker_processes 8;

同一根本问题的答案是https://stackoverflow.com/a/41681414/11296166

【讨论】:

    猜你喜欢
    • 2020-01-01
    • 1970-01-01
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    • 2022-01-11
    • 2018-08-15
    • 2018-10-25
    • 2019-03-22
    相关资源
    最近更新 更多