Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Nginx error "1024 worker_connections are not enough"

My website is running in a Docker Image using Nginx with reverse proxy. Site is working prefectly for many hours under heavy traffic, but eventually it stops working and giving no response with 5** time out error. In AWS Elastic Beanstalks Nginx-log I found this error-message:

[alert] 18037#0: 1024 worker_connections are not enough

I am afraid something is wrong with my custom Nginx-config, but I do not understand what it is. Code from https-redirect-docker-sc.config is attached.

I have tried to debug code to find any memory leaks or loops, but I can not find any solution.

   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;
       }
   }
like image 354
Droabs Avatar asked Oct 22 '25 17:10

Droabs


1 Answers

Default value for Nginx worker_connections is 1024, which is not enough for you.

Add events block before http in your nginx.conf, so it looks like this:

events {
  worker_connections  4096;  ## Default: 1024
}

http {
  include    conf/mime.types;
  .....
}

You can also increase number of worker_processes(default = 1), so the total amount of connections your server can handle would be worker_processes * worker_connections

Please check here the full example configuration

like image 83
andreilozhkin Avatar answered Oct 24 '25 09:10

andreilozhkin