Skip to content

Commit 1eacd3e

Browse files
authored
Merge pull request #51 from tiangolo/custom-nginx-conf
Add support for custom /app/nginx.conf
2 parents 692f8dd + 5de5033 commit 1eacd3e

24 files changed

+610
-380
lines changed

python2.7-alpine3.7/entrypoint.sh

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,48 @@ NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024}
1818
# Get the listen port for Nginx, default to 80
1919
USE_LISTEN_PORT=${LISTEN_PORT:-80}
2020

21-
content='user nginx;\n'
22-
# Set the number of worker processes in Nginx
23-
content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n"
24-
content=$content'error_log /var/log/nginx/error.log warn;\n'
25-
content=$content'pid /var/run/nginx.pid;\n'
26-
content=$content'events {\n'
27-
content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n"
28-
content=$content'}\n'
29-
content=$content'http {\n'
30-
content=$content' include /etc/nginx/mime.types;\n'
31-
content=$content' default_type application/octet-stream;\n'
32-
content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n"
33-
content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n"
34-
content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n"
35-
content=$content' access_log /var/log/nginx/access.log main;\n'
36-
content=$content' sendfile on;\n'
37-
content=$content' keepalive_timeout 65;\n'
38-
content=$content' include /etc/nginx/conf.d/*.conf;\n'
39-
content=$content'}\n'
40-
content=$content'daemon off;\n'
41-
# Set the max number of open file descriptors for Nginx workers, if requested
42-
if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then
43-
content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n"
21+
if [ -f /app/nginx.conf ]; then
22+
cp /app/nginx.conf /etc/nginx/nginx.conf
23+
else
24+
content='user nginx;\n'
25+
# Set the number of worker processes in Nginx
26+
content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n"
27+
content=$content'error_log /var/log/nginx/error.log warn;\n'
28+
content=$content'pid /var/run/nginx.pid;\n'
29+
content=$content'events {\n'
30+
content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n"
31+
content=$content'}\n'
32+
content=$content'http {\n'
33+
content=$content' include /etc/nginx/mime.types;\n'
34+
content=$content' default_type application/octet-stream;\n'
35+
content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n"
36+
content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n"
37+
content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n"
38+
content=$content' access_log /var/log/nginx/access.log main;\n'
39+
content=$content' sendfile on;\n'
40+
content=$content' keepalive_timeout 65;\n'
41+
content=$content' include /etc/nginx/conf.d/*.conf;\n'
42+
content=$content'}\n'
43+
content=$content'daemon off;\n'
44+
# Set the max number of open file descriptors for Nginx workers, if requested
45+
if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then
46+
content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n"
47+
fi
48+
# Save generated /etc/nginx/nginx.conf
49+
printf "$content" > /etc/nginx/nginx.conf
50+
51+
content_server='server {\n'
52+
content_server=$content_server" listen ${USE_LISTEN_PORT};\n"
53+
content_server=$content_server' location / {\n'
54+
content_server=$content_server' include uwsgi_params;\n'
55+
content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n'
56+
content_server=$content_server' }\n'
57+
content_server=$content_server'}\n'
58+
# Save generated server /etc/nginx/conf.d/nginx.conf
59+
printf "$content_server" > /etc/nginx/conf.d/nginx.conf
60+
61+
# Generate Nginx config for maximum upload file size
62+
printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf
4463
fi
45-
# Save generated /etc/nginx/nginx.conf
46-
printf "$content" > /etc/nginx/nginx.conf
47-
48-
content_server='server {\n'
49-
content_server=$content_server" listen ${USE_LISTEN_PORT};\n"
50-
content_server=$content_server' location / {\n'
51-
content_server=$content_server' include uwsgi_params;\n'
52-
content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n'
53-
content_server=$content_server' }\n'
54-
content_server=$content_server'}\n'
55-
# Save generated server /etc/nginx/conf.d/nginx.conf
56-
printf "$content_server" > /etc/nginx/conf.d/nginx.conf
57-
58-
# Generate Nginx config for maximum upload file size
59-
printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf
6064

6165
exec "$@"

python2.7-alpine3.8/entrypoint.sh

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -18,44 +18,48 @@ NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024}
1818
# Get the listen port for Nginx, default to 80
1919
USE_LISTEN_PORT=${LISTEN_PORT:-80}
2020

21-
content='user nginx;\n'
22-
# Set the number of worker processes in Nginx
23-
content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n"
24-
content=$content'error_log /var/log/nginx/error.log warn;\n'
25-
content=$content'pid /var/run/nginx.pid;\n'
26-
content=$content'events {\n'
27-
content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n"
28-
content=$content'}\n'
29-
content=$content'http {\n'
30-
content=$content' include /etc/nginx/mime.types;\n'
31-
content=$content' default_type application/octet-stream;\n'
32-
content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n"
33-
content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n"
34-
content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n"
35-
content=$content' access_log /var/log/nginx/access.log main;\n'
36-
content=$content' sendfile on;\n'
37-
content=$content' keepalive_timeout 65;\n'
38-
content=$content' include /etc/nginx/conf.d/*.conf;\n'
39-
content=$content'}\n'
40-
content=$content'daemon off;\n'
41-
# Set the max number of open file descriptors for Nginx workers, if requested
42-
if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then
43-
content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n"
21+
if [ -f /app/nginx.conf ]; then
22+
cp /app/nginx.conf /etc/nginx/nginx.conf
23+
else
24+
content='user nginx;\n'
25+
# Set the number of worker processes in Nginx
26+
content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n"
27+
content=$content'error_log /var/log/nginx/error.log warn;\n'
28+
content=$content'pid /var/run/nginx.pid;\n'
29+
content=$content'events {\n'
30+
content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n"
31+
content=$content'}\n'
32+
content=$content'http {\n'
33+
content=$content' include /etc/nginx/mime.types;\n'
34+
content=$content' default_type application/octet-stream;\n'
35+
content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n"
36+
content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n"
37+
content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n"
38+
content=$content' access_log /var/log/nginx/access.log main;\n'
39+
content=$content' sendfile on;\n'
40+
content=$content' keepalive_timeout 65;\n'
41+
content=$content' include /etc/nginx/conf.d/*.conf;\n'
42+
content=$content'}\n'
43+
content=$content'daemon off;\n'
44+
# Set the max number of open file descriptors for Nginx workers, if requested
45+
if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then
46+
content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n"
47+
fi
48+
# Save generated /etc/nginx/nginx.conf
49+
printf "$content" > /etc/nginx/nginx.conf
50+
51+
content_server='server {\n'
52+
content_server=$content_server" listen ${USE_LISTEN_PORT};\n"
53+
content_server=$content_server' location / {\n'
54+
content_server=$content_server' include uwsgi_params;\n'
55+
content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n'
56+
content_server=$content_server' }\n'
57+
content_server=$content_server'}\n'
58+
# Save generated server /etc/nginx/conf.d/nginx.conf
59+
printf "$content_server" > /etc/nginx/conf.d/nginx.conf
60+
61+
# Generate Nginx config for maximum upload file size
62+
printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf
4463
fi
45-
# Save generated /etc/nginx/nginx.conf
46-
printf "$content" > /etc/nginx/nginx.conf
47-
48-
content_server='server {\n'
49-
content_server=$content_server" listen ${USE_LISTEN_PORT};\n"
50-
content_server=$content_server' location / {\n'
51-
content_server=$content_server' include uwsgi_params;\n'
52-
content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n'
53-
content_server=$content_server' }\n'
54-
content_server=$content_server'}\n'
55-
# Save generated server /etc/nginx/conf.d/nginx.conf
56-
printf "$content_server" > /etc/nginx/conf.d/nginx.conf
57-
58-
# Generate Nginx config for maximum upload file size
59-
printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf
6064

6165
exec "$@"

python2.7/entrypoint.sh

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,48 @@ NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024}
1414
# Get the listen port for Nginx, default to 80
1515
USE_LISTEN_PORT=${LISTEN_PORT:-80}
1616

17-
content='user nginx;\n'
18-
# Set the number of worker processes in Nginx
19-
content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n"
20-
content=$content'error_log /var/log/nginx/error.log warn;\n'
21-
content=$content'pid /var/run/nginx.pid;\n'
22-
content=$content'events {\n'
23-
content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n"
24-
content=$content'}\n'
25-
content=$content'http {\n'
26-
content=$content' include /etc/nginx/mime.types;\n'
27-
content=$content' default_type application/octet-stream;\n'
28-
content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n"
29-
content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n"
30-
content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n"
31-
content=$content' access_log /var/log/nginx/access.log main;\n'
32-
content=$content' sendfile on;\n'
33-
content=$content' keepalive_timeout 65;\n'
34-
content=$content' include /etc/nginx/conf.d/*.conf;\n'
35-
content=$content'}\n'
36-
content=$content'daemon off;\n'
37-
# Set the max number of open file descriptors for Nginx workers, if requested
38-
if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then
39-
content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n"
17+
if [ -f /app/nginx.conf ]; then
18+
cp /app/nginx.conf /etc/nginx/nginx.conf
19+
else
20+
content='user nginx;\n'
21+
# Set the number of worker processes in Nginx
22+
content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n"
23+
content=$content'error_log /var/log/nginx/error.log warn;\n'
24+
content=$content'pid /var/run/nginx.pid;\n'
25+
content=$content'events {\n'
26+
content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n"
27+
content=$content'}\n'
28+
content=$content'http {\n'
29+
content=$content' include /etc/nginx/mime.types;\n'
30+
content=$content' default_type application/octet-stream;\n'
31+
content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n"
32+
content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n"
33+
content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n"
34+
content=$content' access_log /var/log/nginx/access.log main;\n'
35+
content=$content' sendfile on;\n'
36+
content=$content' keepalive_timeout 65;\n'
37+
content=$content' include /etc/nginx/conf.d/*.conf;\n'
38+
content=$content'}\n'
39+
content=$content'daemon off;\n'
40+
# Set the max number of open file descriptors for Nginx workers, if requested
41+
if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then
42+
content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n"
43+
fi
44+
# Save generated /etc/nginx/nginx.conf
45+
printf "$content" > /etc/nginx/nginx.conf
46+
47+
content_server='server {\n'
48+
content_server=$content_server" listen ${USE_LISTEN_PORT};\n"
49+
content_server=$content_server' location / {\n'
50+
content_server=$content_server' include uwsgi_params;\n'
51+
content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n'
52+
content_server=$content_server' }\n'
53+
content_server=$content_server'}\n'
54+
# Save generated server /etc/nginx/conf.d/nginx.conf
55+
printf "$content_server" > /etc/nginx/conf.d/nginx.conf
56+
57+
# Generate Nginx config for maximum upload file size
58+
printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf
4059
fi
41-
# Save generated /etc/nginx/nginx.conf
42-
printf "$content" > /etc/nginx/nginx.conf
43-
44-
content_server='server {\n'
45-
content_server=$content_server" listen ${USE_LISTEN_PORT};\n"
46-
content_server=$content_server' location / {\n'
47-
content_server=$content_server' include uwsgi_params;\n'
48-
content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n'
49-
content_server=$content_server' }\n'
50-
content_server=$content_server'}\n'
51-
# Save generated server /etc/nginx/conf.d/nginx.conf
52-
printf "$content_server" > /etc/nginx/conf.d/nginx.conf
53-
54-
# Generate Nginx config for maximum upload file size
55-
printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf
5660

5761
exec "$@"

python3.5/entrypoint.sh

Lines changed: 42 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -14,44 +14,48 @@ NGINX_WORKER_CONNECTIONS=${NGINX_WORKER_CONNECTIONS:-1024}
1414
# Get the listen port for Nginx, default to 80
1515
USE_LISTEN_PORT=${LISTEN_PORT:-80}
1616

17-
content='user nginx;\n'
18-
# Set the number of worker processes in Nginx
19-
content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n"
20-
content=$content'error_log /var/log/nginx/error.log warn;\n'
21-
content=$content'pid /var/run/nginx.pid;\n'
22-
content=$content'events {\n'
23-
content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n"
24-
content=$content'}\n'
25-
content=$content'http {\n'
26-
content=$content' include /etc/nginx/mime.types;\n'
27-
content=$content' default_type application/octet-stream;\n'
28-
content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n"
29-
content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n"
30-
content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n"
31-
content=$content' access_log /var/log/nginx/access.log main;\n'
32-
content=$content' sendfile on;\n'
33-
content=$content' keepalive_timeout 65;\n'
34-
content=$content' include /etc/nginx/conf.d/*.conf;\n'
35-
content=$content'}\n'
36-
content=$content'daemon off;\n'
37-
# Set the max number of open file descriptors for Nginx workers, if requested
38-
if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then
39-
content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n"
17+
if [ -f /app/nginx.conf ]; then
18+
cp /app/nginx.conf /etc/nginx/nginx.conf
19+
else
20+
content='user nginx;\n'
21+
# Set the number of worker processes in Nginx
22+
content=$content"worker_processes ${USE_NGINX_WORKER_PROCESSES};\n"
23+
content=$content'error_log /var/log/nginx/error.log warn;\n'
24+
content=$content'pid /var/run/nginx.pid;\n'
25+
content=$content'events {\n'
26+
content=$content" worker_connections ${NGINX_WORKER_CONNECTIONS};\n"
27+
content=$content'}\n'
28+
content=$content'http {\n'
29+
content=$content' include /etc/nginx/mime.types;\n'
30+
content=$content' default_type application/octet-stream;\n'
31+
content=$content' log_format main '"'\$remote_addr - \$remote_user [\$time_local] \"\$request\" '\n"
32+
content=$content' '"'\$status \$body_bytes_sent \"\$http_referer\" '\n"
33+
content=$content' '"'\"\$http_user_agent\" \"\$http_x_forwarded_for\"';\n"
34+
content=$content' access_log /var/log/nginx/access.log main;\n'
35+
content=$content' sendfile on;\n'
36+
content=$content' keepalive_timeout 65;\n'
37+
content=$content' include /etc/nginx/conf.d/*.conf;\n'
38+
content=$content'}\n'
39+
content=$content'daemon off;\n'
40+
# Set the max number of open file descriptors for Nginx workers, if requested
41+
if [ -n "${NGINX_WORKER_OPEN_FILES}" ] ; then
42+
content=$content"worker_rlimit_nofile ${NGINX_WORKER_OPEN_FILES};\n"
43+
fi
44+
# Save generated /etc/nginx/nginx.conf
45+
printf "$content" > /etc/nginx/nginx.conf
46+
47+
content_server='server {\n'
48+
content_server=$content_server" listen ${USE_LISTEN_PORT};\n"
49+
content_server=$content_server' location / {\n'
50+
content_server=$content_server' include uwsgi_params;\n'
51+
content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n'
52+
content_server=$content_server' }\n'
53+
content_server=$content_server'}\n'
54+
# Save generated server /etc/nginx/conf.d/nginx.conf
55+
printf "$content_server" > /etc/nginx/conf.d/nginx.conf
56+
57+
# Generate Nginx config for maximum upload file size
58+
printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf
4059
fi
41-
# Save generated /etc/nginx/nginx.conf
42-
printf "$content" > /etc/nginx/nginx.conf
43-
44-
content_server='server {\n'
45-
content_server=$content_server" listen ${USE_LISTEN_PORT};\n"
46-
content_server=$content_server' location / {\n'
47-
content_server=$content_server' include uwsgi_params;\n'
48-
content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n'
49-
content_server=$content_server' }\n'
50-
content_server=$content_server'}\n'
51-
# Save generated server /etc/nginx/conf.d/nginx.conf
52-
printf "$content_server" > /etc/nginx/conf.d/nginx.conf
53-
54-
# Generate Nginx config for maximum upload file size
55-
printf "client_max_body_size $USE_NGINX_MAX_UPLOAD;\n" > /etc/nginx/conf.d/upload.conf
5660

5761
exec "$@"

0 commit comments

Comments
 (0)