Skip to content

Commit a78e4f6

Browse files
authored
Merge pull request #56 from ronlut/master
Add worker_rlimit_nofile and worker_connections support to nginx config
2 parents 4398728 + 369a486 commit a78e4f6

File tree

6 files changed

+77
-0
lines changed

6 files changed

+77
-0
lines changed

README.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -499,6 +499,28 @@ ENV NGINX_WORKER_PROCESSES auto
499499
COPY ./app /app
500500
```
501501

502+
## Custom Nginx maximum connections per worker
503+
504+
By default, Nginx will start with a maximum limit of 1024 connections per worker.
505+
506+
If you want to set a different number you can use the environment variable `NGINX_WORKER_CONNECTIONS`, e.g:
507+
508+
```Dockerfile
509+
ENV NGINX_WORKER_CONNECTIONS 2048
510+
```
511+
512+
It cannot exceed the current limit on the maximum number of open files. See how to configure it in the next section.
513+
514+
## Custom Nginx maximum open files
515+
516+
The number connections per Nginx worker cannot exceed the limit on the maximum number of open files.
517+
518+
You can change the limit of open files with the environment variable `NGINX_WORKER_OPEN_FILES`, e.g.:
519+
520+
```Dockerfile
521+
ENV NGINX_WORKER_OPEN_FILES 2048
522+
```
523+
502524
## Customizing Nginx configurations
503525

504526
If you need to configure Nginx further, you can add `*.conf` files to `/etc/nginx/conf.d/` in your Dockerfile.

python2.7-alpine3.7/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
1010
# Modify the number of worker processes in Nginx config
1111
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf
1212

13+
# Set the max number of connections per worker for Nginx, if requested
14+
# Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below
15+
if [[ -v NGINX_WORKER_CONNECTIONS ]] ; then
16+
sed -i "/worker_connections\s/c\ worker_connections ${NGINX_WORKER_CONNECTIONS};" /etc/nginx/nginx.conf
17+
fi
18+
19+
# Set the max number of open file descriptors for Nginx workers, if requested
20+
if [[ -v NGINX_WORKER_OPEN_FILES ]] ; then
21+
echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf
22+
fi
23+
1324
# Get the URL for static files from the environment variable
1425
USE_STATIC_URL=${STATIC_URL:-'/static'}
1526
# Get the absolute path of the static files from the environment variable

python2.7/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
1010
# Modify the number of worker processes in Nginx config
1111
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf
1212

13+
# Set the max number of connections per worker for Nginx, if requested
14+
# Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below
15+
if [[ -v NGINX_WORKER_CONNECTIONS ]] ; then
16+
sed -i "/worker_connections\s/c\ worker_connections ${NGINX_WORKER_CONNECTIONS};" /etc/nginx/nginx.conf
17+
fi
18+
19+
# Set the max number of open file descriptors for Nginx workers, if requested
20+
if [[ -v NGINX_WORKER_OPEN_FILES ]] ; then
21+
echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf
22+
fi
23+
1324
# Get the URL for static files from the environment variable
1425
USE_STATIC_URL=${STATIC_URL:-'/static'}
1526
# Get the absolute path of the static files from the environment variable

python3.5/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
1010
# Modify the number of worker processes in Nginx config
1111
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf
1212

13+
# Set the max number of connections per worker for Nginx, if requested
14+
# Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below
15+
if [[ -v NGINX_WORKER_CONNECTIONS ]] ; then
16+
sed -i "/worker_connections\s/c\ worker_connections ${NGINX_WORKER_CONNECTIONS};" /etc/nginx/nginx.conf
17+
fi
18+
19+
# Set the max number of open file descriptors for Nginx workers, if requested
20+
if [[ -v NGINX_WORKER_OPEN_FILES ]] ; then
21+
echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf
22+
fi
23+
1324
# Get the URL for static files from the environment variable
1425
USE_STATIC_URL=${STATIC_URL:-'/static'}
1526
# Get the absolute path of the static files from the environment variable

python3.6-alpine3.7/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
1010
# Modify the number of worker processes in Nginx config
1111
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf
1212

13+
# Set the max number of connections per worker for Nginx, if requested
14+
# Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below
15+
if [[ -v NGINX_WORKER_CONNECTIONS ]] ; then
16+
sed -i "/worker_connections\s/c\ worker_connections ${NGINX_WORKER_CONNECTIONS};" /etc/nginx/nginx.conf
17+
fi
18+
19+
# Set the max number of open file descriptors for Nginx workers, if requested
20+
if [[ -v NGINX_WORKER_OPEN_FILES ]] ; then
21+
echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf
22+
fi
23+
1324
# Get the URL for static files from the environment variable
1425
USE_STATIC_URL=${STATIC_URL:-'/static'}
1526
# Get the absolute path of the static files from the environment variable

python3.6/entrypoint.sh

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,17 @@ USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
1010
# Modify the number of worker processes in Nginx config
1111
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf
1212

13+
# Set the max number of connections per worker for Nginx, if requested
14+
# Cannot exceed worker_rlimit_nofile, see NGINX_WORKER_OPEN_FILES below
15+
if [[ -v NGINX_WORKER_CONNECTIONS ]] ; then
16+
sed -i "/worker_connections\s/c\ worker_connections ${NGINX_WORKER_CONNECTIONS};" /etc/nginx/nginx.conf
17+
fi
18+
19+
# Set the max number of open file descriptors for Nginx workers, if requested
20+
if [[ -v NGINX_WORKER_OPEN_FILES ]] ; then
21+
echo "worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};" >> /etc/nginx/nginx.conf
22+
fi
23+
1324
# Get the URL for static files from the environment variable
1425
USE_STATIC_URL=${STATIC_URL:-'/static'}
1526
# Get the absolute path of the static files from the environment variable

0 commit comments

Comments
 (0)