|
| 1 | +#! /usr/bin/env sh |
| 2 | +set -e |
| 3 | + |
| 4 | +/uwsgi-nginx-entrypoint.sh |
| 5 | + |
| 6 | +# Get the URL for static files from the environment variable |
| 7 | +USE_STATIC_URL=${STATIC_URL:-'/static'} |
| 8 | +# Get the absolute path of the static files from the environment variable |
| 9 | +USE_STATIC_PATH=${STATIC_PATH:-'/app/static'} |
| 10 | +# Get the listen port for Nginx, default to 80 |
| 11 | +USE_LISTEN_PORT=${LISTEN_PORT:-80} |
| 12 | + |
| 13 | +if [ -f /app/nginx.conf ]; then |
| 14 | + cp /app/nginx.conf /etc/nginx/nginx.conf |
| 15 | +else |
| 16 | + content_server='server {\n' |
| 17 | + content_server=$content_server" listen ${USE_LISTEN_PORT};\n" |
| 18 | + content_server=$content_server' location / {\n' |
| 19 | + content_server=$content_server' try_files $uri @app;\n' |
| 20 | + content_server=$content_server' }\n' |
| 21 | + content_server=$content_server' location @app {\n' |
| 22 | + content_server=$content_server' include uwsgi_params;\n' |
| 23 | + content_server=$content_server' uwsgi_pass unix:///tmp/uwsgi.sock;\n' |
| 24 | + content_server=$content_server' }\n' |
| 25 | + content_server=$content_server" location $USE_STATIC_URL {\n" |
| 26 | + content_server=$content_server" alias $USE_STATIC_PATH;\n" |
| 27 | + content_server=$content_server' }\n' |
| 28 | + # If STATIC_INDEX is 1, serve / with /static/index.html directly (or the static URL configured) |
| 29 | + if [ "$STATIC_INDEX" = 1 ] ; then |
| 30 | + content_server=$content_server' location = / {\n' |
| 31 | + content_server=$content_server" index $USE_STATIC_URL/index.html;\n" |
| 32 | + content_server=$content_server' }\n' |
| 33 | + fi |
| 34 | + content_server=$content_server'}\n' |
| 35 | + # Save generated server /etc/nginx/conf.d/nginx.conf |
| 36 | + printf "$content_server" > /etc/nginx/conf.d/nginx.conf |
| 37 | +fi |
| 38 | + |
| 39 | +# For Alpine: |
| 40 | +# Explicitly add installed Python packages and uWSGI Python packages to PYTHONPATH |
| 41 | +# Otherwise uWSGI can't import Flask |
| 42 | +if [ -n "$ALPINEPYTHON" ] ; then |
| 43 | + export PYTHONPATH=$PYTHONPATH:/usr/local/lib/$ALPINEPYTHON/site-packages:/usr/lib/$ALPINEPYTHON/site-packages |
| 44 | +fi |
| 45 | + |
| 46 | +exec "$@" |
0 commit comments