【问题标题】:Django and nginx - docker - problem with adding add worker_connections. nginx - directive is not allowed hereDjango 和 nginx - docker - 添加添加 worker_connections 的问题。 nginx - 此处不允许使用指令
【发布时间】:2020-10-03 05:52:15
【问题描述】:

我在将 nginx 工作程序连接添加到配置时遇到问题

这是我的配置 nginx

worker_processes 1;

events {
  worker_connections 10240; # increase if you have lots of clients
}
http {

  upstream my-app {
    server web-prod: 8000;
  }

  server {
    listen 80;
    server_name my-app.com;
    client_max_body_size 4G;

    access_log off;

    gzip on;
    gzip_min_length 10240;
    gzip_comp_level 1;
    gzip_vary on;
    gzip_proxied expired no-cache no-store private auth;
    gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml application/atom+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;

    # allow the server to close connection on non responding client, this will free up memory
    reset_timedout_connection on;

    # request timed out -- default 60
    client_body_timeout 10;

    # if client stop responding, free up memory -- default 60
    send_timeout 2;

    # server will close connection after this time -- default 75
    keepalive_timeout 30;

    # number of requests client can make over keep-alive -- for testing environment
    keepalive_requests 100000;

    location / {
      proxy_pass http://my-app;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
      proxy_set_header Host $host;
      proxy_redirect off;
    }

    location /staticfiles/ {
      alias /usr/src/app/my-app/staticfiles/;
      expires 365d;
    }
    location /mediafiles/ {
      alias /home/app/web/mediafiles/;
    }
  }
}

我的 dockerfile nginx

FROM nginx:stable

RUN rm /etc/nginx/conf.d/default.conf
COPY nginx.conf /etc/nginx/conf.d

错误 nginx

nginx: [emerg] "worker_processes" directive is not allowed here in /etc/nginx/conf.d/nginx.conf:1

我猜我的 dockerfile 和配置 nginx 文件有问题。 我尝试了很多配置,我在很多页面上都在寻找问题,但我现在找不到解决方案。 我会很感激你的提示

【问题讨论】:

    标签: python django docker nginx


    【解决方案1】:

    我的问题解决了

    Dockerfile

    FROM nginx:stable
    
    ADD nginx.conf /etc/nginx/nginx.conf
    COPY ./conf /etc/nginx/sites-enabled
    

    nginx.conf

    user nginx;
    
    worker_processes  5;  ## Default: 1
    worker_rlimit_nofile 8192;
    
    events {
      worker_connections  10240;  ## Default: 1024
    }
    http {
      include /etc/nginx/sites-enabled/*;
    }
    

    my-app.conf

    upstream my-app {
        server web-prod:8000;
    }
    
    server {
        listen 80;
        server_name my-app.com;
        client_max_body_size 4G;
    
        access_log off;
    
        gzip on;
        gzip_min_length 10240;
        gzip_comp_level 1;
        gzip_vary on;
        gzip_proxied expired no-cache no-store private auth;
        gzip_types text/css text/javascript text/xml text/plain text/x-component application/javascript application/x-javascript application/json application/xml application/rss+xml application/atom+xml font/truetype font/opentype application/vnd.ms-fontobject image/svg+xml;
    
        # allow the server to close connection on non responding client, this will free up memory
        reset_timedout_connection on;
    
        # request timed out -- default 60
        client_body_timeout 10;
    
        # if client stop responding, free up memory -- default 60
        send_timeout 2;
    
        # server will close connection after this time -- default 75
        keepalive_timeout 30;
    
        # number of requests client can make over keep-alive -- for testing environment
        keepalive_requests 100000;
    
        location / {
            proxy_pass http://my-app;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host $host;
            proxy_redirect off;
            client_max_body_size    10m;
            client_body_buffer_size 128k;
            proxy_connect_timeout   90;
            proxy_send_timeout      90;
            proxy_read_timeout      90;
            proxy_buffers           32 4k;
        }
    
        location /staticfiles/ {
            alias /usr/src/app/my-app/staticfiles/;
            expires 365d;
        }
        location /mediafiles/ {
            alias /home/app/web/mediafiles/;
        }
    }
    

    和我的结构

    【讨论】:

      【解决方案2】:

      我认为在您的 /etc/nginx/ 目录中有一个主要的 nginx 配置文件 /etc/nginx/nginx.conf,在 http 上下文中存在以下行:

      http {
          ...
          include  /etc/nginx/conf.d/*.conf
          ...
      

      因此,您的 worker_processes 指令转到 http 上下文,而不是您可能认为的主要上下文。要查看主要的 nginx 配置文件是什么,请运行 nginx -V 并查看 --conf-path= 构建选项值。

      【讨论】:

      • 对不起,我还是不明白该怎么做
      猜你喜欢
      • 2014-10-08
      • 2019-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-25
      • 2014-02-24
      相关资源
      最近更新 更多