diff --git a/confs/site/reverse-proxy.conf b/confs/site/reverse-proxy.conf new file mode 100644 index 0000000..50a5eae --- /dev/null +++ b/confs/site/reverse-proxy.conf @@ -0,0 +1,7 @@ +proxy_set_header Host $host; +proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +proxy_set_header X-Real-IP $remote_addr; + +location %REVERSE_PROXY_URL% { + proxy_pass %REVERSE_PROXY_LOCATION%; +} diff --git a/confs/site/server.conf b/confs/site/server.conf index c9a4fe6..cdf55bc 100644 --- a/confs/site/server.conf +++ b/confs/site/server.conf @@ -38,4 +38,5 @@ server { server_tokens %SERVER_TOKENS%; %USE_OPEN_FILE_CACHE% %USE_PROXY_CACHE% + %USE_REVERSE_PROXY% } diff --git a/entrypoint/defaults.sh b/entrypoint/defaults.sh index 9d6b02d..def59de 100644 --- a/entrypoint/defaults.sh +++ b/entrypoint/defaults.sh @@ -31,6 +31,7 @@ BROTLI_COMP_LEVEL="${BROTLI_COMP_LEVEL-6}" BROTLI_MIN_LENGTH="${BROTLI_MIN_LENGTH-1000}" BROTLI_TYPES="${BROTLI_TYPES-application/atom+xml application/javascript application/json application/rss+xml application/vnd.ms-fontobject application/x-font-opentype application/x-font-truetype application/x-font-ttf application/x-javascript application/xhtml+xml application/xml font/eot font/opentype font/otf font/truetype image/svg+xml image/vnd.microsoft.icon image/x-icon image/x-win-bitmap text/css text/javascript text/plain text/xml}" REMOTE_PHP_PATH="${REMOTE_PHP_PATH-/app}" +USE_REVERSE_PROXY="${USE_REVERSE_PROXY-no}" HEADER_SERVER="${HEADER_SERVER-no}" X_FRAME_OPTIONS="${X_FRAME_OPTIONS-DENY}" X_XSS_PROTECTION="${X_XSS_PROTECTION-1; mode=block}" diff --git a/entrypoint/global-config.sh b/entrypoint/global-config.sh index 175d7ca..2d9f49f 100644 --- a/entrypoint/global-config.sh +++ b/entrypoint/global-config.sh @@ -32,7 +32,7 @@ else fi # proxy_cache zone -if [ "$USE_PROXY_CACHE" = "yes" ] ; then +if [ "$(has_value USE_PROXY_CACHE yes)" = "yes" ] ; then replace_in_file "/etc/nginx/nginx.conf" "%PROXY_CACHE_PATH%" "proxy_cache_path /tmp/proxy_cache keys_zone=proxycache:${PROXY_CACHE_PATH_ZONE_SIZE} ${PROXY_CACHE_PATH_PARAMS};" else replace_in_file "/etc/nginx/nginx.conf" "%PROXY_CACHE_PATH%" "" diff --git a/entrypoint/site-config.sh b/entrypoint/site-config.sh index 47c84ce..0349d20 100644 --- a/entrypoint/site-config.sh +++ b/entrypoint/site-config.sh @@ -42,6 +42,16 @@ replace_in_file "{NGINX_PREFIX}server.conf" "%MAX_CLIENT_SIZE%" "$MAX_CLIENT_SIZ # server tokens replace_in_file "{NGINX_PREFIX}server.conf" "%SERVER_TOKENS%" "$SERVER_TOKENS" +# reverse proxy +if [ "$USE_REVERSE_PROXY" = "yes" ] ; then + replace_in_file "${NGINX_PREFIX}server.conf" "%USE_REVERSE_PROXY%" "include ${NGINX_PREFIX}reverse-proxy.conf" + replace_in_file "${NGINX_PREFIX}reverse-proxy.conf" "%REVERSE_PROXY_URL%" "$REVERSE_PROXY_URL" + replace_in_file "${NGINX_PREFIX}reverse-proxy.conf" "%REVERSE_PROXY_HOST%" "$REVERSE_PROXY_HOST" + +else + replace_in_file "${NGINX_PREFIX}server.conf" "%USE_REVERSE_PROXY%" "" +fi + # proxy caching if [ "$USE_PROXY_CACHE" = "yes" ] ; then replace_in_file "${NGINX_PREFIX}server.conf" "%USE_PROXY_CACHE%" "include ${NGINX_PREFIX}proxy-cache.conf;"