Skip to content

Commit 6bda98b

Browse files
authored
Merge pull request #22 from naktinis/master
Allow setting the number of Nginx worker processes via an environment variable `NGINX_WORKER_PROCESSES`
2 parents 15c791d + 64856e4 commit 6bda98b

File tree

10 files changed

+50
-7
lines changed

10 files changed

+50
-7
lines changed

python2.7-alpine3.7/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ ENV UWSGI_INI /app/uwsgi.ini
170170
ENV NGINX_MAX_UPLOAD 1m
171171
ENV NGINX_MAX_UPLOAD 0
172172

173+
# By default, Nginx will run a single worker process, setting it to auto
174+
# will create a worker for each CPU core
175+
ENV NGINX_WORKER_PROCESSES 1
176+
173177
# By default, Nginx listens on port 80.
174178
# To modify this, change LISTEN_PORT environment variable.
175179
# (in a Dockerfile or with an option for `docker run`)

python2.7-alpine3.7/entrypoint.sh

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,18 @@ USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0}
66
# Generate Nginx config for maximum upload file size
77
echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.conf
88

9-
# Get the listen port for Nginx, default to 80
10-
USE_LISTEN_PORT=${LISTEN_PORT:-80}
11-
129
# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH
1310
# Otherwise uWSGI can't import Flask
1411
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python2.7/site-packages:/usr/lib/python2.7/site-packages
1512

16-
# Modify Nignx config for listen port
13+
# Get the number of workers for Nginx, default to 1
14+
USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
15+
# Modify the number of worker processes in Nginx config
16+
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf
17+
18+
# Get the listen port for Nginx, default to 80
19+
USE_LISTEN_PORT=${LISTEN_PORT:-80}
20+
# Modify Nginx config for listen port
1721
if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then
1822
sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf
1923
fi

python2.7/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ ENV UWSGI_INI /app/uwsgi.ini
4141
# ENV NGINX_MAX_UPLOAD 1m
4242
ENV NGINX_MAX_UPLOAD 0
4343

44+
# By default, Nginx will run a single worker process, setting it to auto
45+
# will create a worker for each CPU core
46+
ENV NGINX_WORKER_PROCESSES 1
47+
4448
# By default, Nginx listens on port 80.
4549
# To modify this, change LISTEN_PORT environment variable.
4650
# (in a Dockerfile or with an option for `docker run`)

python2.7/entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0}
66
# Generate Nginx config for maximum upload file size
77
echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.conf
88

9+
# Get the number of workers for Nginx, default to 1
10+
USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
11+
# Modify the number of worker processes in Nginx config
12+
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf
13+
914
# Get the listen port for Nginx, default to 80
1015
USE_LISTEN_PORT=${LISTEN_PORT:-80}
1116
# Modify Nignx config for listen port

python3.5/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,10 @@ ENV UWSGI_INI /app/uwsgi.ini
4141
# ENV NGINX_MAX_UPLOAD 1m
4242
ENV NGINX_MAX_UPLOAD 0
4343

44+
# By default, Nginx will run a single worker process, setting it to auto
45+
# will create a worker for each CPU core
46+
ENV NGINX_WORKER_PROCESSES 1
47+
4448
# By default, Nginx listens on port 80.
4549
# To modify this, change LISTEN_PORT environment variable.
4650
# (in a Dockerfile or with an option for `docker run`)

python3.5/entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0}
66
# Generate Nginx config for maximum upload file size
77
echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.conf
88

9+
# Get the number of workers for Nginx, default to 1
10+
USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
11+
# Modify the number of worker processes in Nginx config
12+
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf
13+
914
# Get the listen port for Nginx, default to 80
1015
USE_LISTEN_PORT=${LISTEN_PORT:-80}
1116
# Modify Nignx config for listen port

python3.6-alpine3.7/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,10 @@ ENV UWSGI_INI /app/uwsgi.ini
170170
ENV NGINX_MAX_UPLOAD 1m
171171
ENV NGINX_MAX_UPLOAD 0
172172

173+
# By default, Nginx will run a single worker process, setting it to auto
174+
# will create a worker for each CPU core
175+
ENV NGINX_WORKER_PROCESSES 1
176+
173177
# By default, Nginx listens on port 80.
174178
# To modify this, change LISTEN_PORT environment variable.
175179
# (in a Dockerfile or with an option for `docker run`)

python3.6-alpine3.7/entrypoint.sh

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,17 @@ USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0}
66
# Generate Nginx config for maximum upload file size
77
echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.conf
88

9-
# Get the listen port for Nginx, default to 80
10-
USE_LISTEN_PORT=${LISTEN_PORT:-80}
11-
129
# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH
1310
# Otherwise uWSGI can't import Flask
1411
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/python3.6/site-packages:/usr/lib/python3.6/site-packages
1512

13+
# Get the number of workers for Nginx, default to 1
14+
USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
15+
# Modify the number of worker processes in Nginx config
16+
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf
17+
18+
# Get the listen port for Nginx, default to 80
19+
USE_LISTEN_PORT=${LISTEN_PORT:-80}
1620
# Modify Nignx config for listen port
1721
if ! grep -q "listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf ; then
1822
sed -i -e "/server {/a\ listen ${USE_LISTEN_PORT};" /etc/nginx/conf.d/nginx.conf

python3.6/Dockerfile

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ ENV UWSGI_INI /app/uwsgi.ini
123123
# ENV NGINX_MAX_UPLOAD 1m
124124
ENV NGINX_MAX_UPLOAD 0
125125

126+
# By default, Nginx will run a single worker process, setting it to auto
127+
# will create a worker for each CPU core
128+
ENV NGINX_WORKER_PROCESSES 1
129+
126130
# By default, Nginx listens on port 80.
127131
# To modify this, change LISTEN_PORT environment variable.
128132
# (in a Dockerfile or with an option for `docker run`)

python3.6/entrypoint.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,11 @@ USE_NGINX_MAX_UPLOAD=${NGINX_MAX_UPLOAD:-0}
66
# Generate Nginx config for maximum upload file size
77
echo "client_max_body_size $USE_NGINX_MAX_UPLOAD;" > /etc/nginx/conf.d/upload.conf
88

9+
# Get the number of workers for Nginx, default to 1
10+
USE_NGINX_WORKER_PROCESSES=${NGINX_WORKER_PROCESSES:-1}
11+
# Modify the number of worker processes in Nginx config
12+
sed -i "/worker_processes\s/c\worker_processes ${USE_NGINX_WORKER_PROCESSES};" /etc/nginx/nginx.conf
13+
914
# Get the listen port for Nginx, default to 80
1015
USE_LISTEN_PORT=${LISTEN_PORT:-80}
1116
# Modify Nignx config for listen port

0 commit comments

Comments
 (0)