【问题标题】:Nginx error "1024 worker_connections are not enough"Nginx 错误“1024 worker_connections 不够”
【发布时间】:2019-11-05 11:39:58
【问题描述】:

我的网站在使用 Nginx 和反向代理的 Docker 映像中运行。 网站在交通繁忙的情况下可以正常工作数小时,但最终它停止工作并且没有响应并出现 5** 超时错误。 在 AWS Elastic Beanstalks Nginx-log 中,我发现了这个错误消息:

[alert] 18037#0: 1024 worker_connections 不够

恐怕我的自定义 Nginx 配置有问题, 但我不明白它是什么。 附上来自 https-redirect-docker-sc.config 的代码。

我尝试调试代码以查找任何内存泄漏或循环,但找不到任何解决方案。

   files:
   "/etc/nginx/sites-available/elasticbeanstalk-nginx-docker-proxy.conf":
   owner: root
   group: root
   mode: "000755"
   content: |
   map $http_upgrade $connection_upgrade {
          default        "upgrade";
          ""            "";
   }

   server {
       listen 80;
       server_name mydomain.no;

       return 301 https://www.mydomain.no$request_uri;
   }   

   server {
       listen 80 default_server;

       gzip on;
       gzip_comp_level 4;
       gzip_types text/html text/plain text/css application/json application/x-javascript text/xml application/xml application/xml+rss text/javascript;

       if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})T(\d{2})") {
           set $year $1;
           set $month $2;
           set $day $3;
           set $hour $4;
       }
       access_log /var/log/nginx/healthd/application.log.$year-$month-$day-$hour healthd;

       access_log    /var/log/nginx/access.log;

       location / {
           set $redirect 0;
           if ($http_x_forwarded_proto != "https") {
             set $redirect 1;
           }
           if ($http_user_agent ~* "ELB-HealthChecker") {
             set $redirect 0;
           }
           if ($redirect = 1) {
             return 301 https://$host$request_uri;
           }

           proxy_pass            http://docker;
           proxy_http_version    1.1;

           proxy_set_header    Connection            $connection_upgrade;
           proxy_set_header    Upgrade                $http_upgrade;
           proxy_set_header    Host                $host;
           proxy_set_header    X-Real-IP            $remote_addr;
           proxy_set_header    X-Forwarded-For        $proxy_add_x_forwarded_for;
       }
   }

【问题讨论】:

    标签: amazon-web-services nginx amazon-elastic-beanstalk nginx-reverse-proxy


    【解决方案1】:

    Nginx worker_connections 的默认值为 1024,这对你来说还不够。

    在你的 nginx.conf 中的 http 之前添加事件块,所以它看起来像这样:

    events {
      worker_connections  4096;  ## Default: 1024
    }
    
    http {
      include    conf/mime.types;
      .....
    }
    

    您还可以增加 worker_processes 的数量(默认 = 1),因此您的服务器可以处理的连接总数为 worker_processes * worker_connections

    请在此处查看full example configuration

    【讨论】:

    • `include conf/mime.types;`有什么好处
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-31
    • 1970-01-01
    • 1970-01-01
    • 2014-07-13
    • 2021-06-27
    • 2023-03-04
    相关资源
    最近更新 更多