Upon diving into the EC2 server's logs, I found the following log message spammed across the file:
1024 worker_connections are not enough
I then understood that I need to tweak the worker_connections
declaration in /etc/nginx/nginx.conf
, as well as the increase OS file descriptor limit, since each connection requires 1 file descriptor.
You can check the OS file descriptor limit by running:
ulimit -n
However, since the instance is managed by Elastic Beanstalk, Amazon asks that we instead make our edits to /tmp/deployment/config/#etc#nginx#nginx.conf
, which contains the same content as /etc/nginx/nginx.conf
, but Amazon knows to copy it over to /etc/nginx/nginx.conf
when the deploy completes, as well as tell nginx
to use the new configuration.
I created an .ebextensions file that increases the OS file descriptor limit, as well as the worker_connections
declaration. Increasing this limit will allow us to support sudden spikes of traffic instead of returning ECONNRESET
.
Include it with your application when you deploy, in the following path relative to the root directory of your deployed directory:
.ebextensions/nginx.config
files:
"/etc/security/limits.conf":
content: |
* soft nofile 6144
* hard nofile 6144
container_commands:
01-worker-connections:
command: "/bin/sed -i 's/worker_connections 1024/worker_connections 6144/g' /tmp/deployment/config/#etc#nginx#nginx.conf"