-
Notifications
You must be signed in to change notification settings - Fork 26
/
uwsgi-nginx-entrypoint.sh
57 lines (50 loc) · 2.63 KB
/
uwsgi-nginx-entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#! /usr/bin/env sh
set -e
/uwsgi-nginx-entrypoint.sh
# Modified from the bash script in the base image. See initial version here: https://github.com/tiangolo/uwsgi-nginx-flask-docker/blob/master/docker-images/entrypoint.sh
# Get the URL for static files from the environment variable
USE_STATIC_URL=${STATIC_URL:-'/static'}
# Get the absolute path of the static files from the environment variable
USE_STATIC_PATH=${STATIC_PATH:-'/app/static'}
# Get the listen port for Nginx, default to 80
USE_LISTEN_PORT=${LISTEN_PORT:-80}
if [ -f /app/nginx.conf ]; then
cp /app/nginx.conf /etc/nginx/nginx.conf
else
content_server='server {\n'
content_server=$content_server" listen ${USE_LISTEN_PORT} default_server;\n"
content_server=$content_server" listen [::]:${USE_LISTEN_PORT} default_server;\n"
content_server=$content_server' server_name 127.0.0.1;\n'
content_server=$content_server' proxy_read_timeout 300;\n'
content_server=$content_server' proxy_connect_timeout 300;\n'
content_server=$content_server' proxy_send_timeout 300;\n'
content_server=$content_server' send_timeout 300;\n'
content_server=$content_server' uwsgi_read_timeout 300;\n'
content_server=$content_server' location / {\n'
content_server=$content_server' try_files $uri @app;\n'
content_server=$content_server' }\n'
content_server=$content_server' location @app {\n'
content_server=$content_server' include uwsgi_params;\n'
content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n'
content_server=$content_server' }\n'
content_server=$content_server" location $USE_STATIC_URL {\n"
content_server=$content_server" alias $USE_STATIC_PATH;\n"
content_server=$content_server' }\n'
content_server=$content_server' return 302 https://$server_name$request_uri;\n'
# If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured)
if [ "$STATIC_INDEX" = 1 ] ; then
content_server=$content_server' location = / {\n'
content_server=$content_server" index $USE_STATIC_URL/index.html;\n"
content_server=$content_server' }\n'
fi
content_server=$content_server'}\n'
# Save generated server /etc/nginx/conf.d/nginx.conf
printf "$content_server" > /etc/nginx/conf.d/nginx.conf
fi
# For Alpine:
# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH
# Otherwise uWSGI can't import Flask
if [ -n "$ALPINEPYTHON" ] ; then
export PYTHONPATH=$PYTHONPATH:/usr/local/lib/$ALPINEPYTHON/site-packages:/usr/lib/$ALPINEPYTHON/site-packages
fi
exec "$@"