diff --git a/README.md b/README.md index 1f406dd..198c292 100644 --- a/README.md +++ b/README.md @@ -11,6 +11,8 @@ A very simple container to redirect HTTP traffic to another server, based on `ng ### Environment variables - `SERVER_REDIRECT` - server to redirect to, eg. `www.example.com` +- `SERVER_NAME` - optionally define the server name to listen on eg. `~^www.(?.+).example.com` + useful for capturing variable to use in server_redirect. - `SERVER_REDIRECT_PATH` - optionally define path to redirect all requests eg. `/landingpage` if not set nginx var `$request_uri` is used - `SERVER_REDIRECT_SCHEME` - optionally define scheme to redirect to diff --git a/default.conf b/default.conf index a3ed6fa..6e0b0d6 100644 --- a/default.conf +++ b/default.conf @@ -1,6 +1,6 @@ server { listen 80; - server_name localhost; + server_name ${SERVER_NAME}; return ${SERVER_REDIRECT_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH}; diff --git a/run.sh b/run.sh index 1f81126..d06824b 100644 --- a/run.sh +++ b/run.sh @@ -5,6 +5,11 @@ if [ ! -n "$SERVER_REDIRECT" ] ; then exit 1 fi +# set server name from optional ENV var +if [ ! -n "$SERVER_NAME" ] ; then + SERVER_NAME='localhost' +fi + # set redirect code from optional ENV var if [ "$SERVER_REDIRECT_CODE" != '302' ] ; then SERVER_REDIRECT_CODE='301' @@ -21,6 +26,7 @@ if [ ! -n "$SERVER_REDIRECT_SCHEME" ] ; then fi sed -i "s|\${SERVER_REDIRECT}|${SERVER_REDIRECT}|" /etc/nginx/conf.d/default.conf +sed -i "s|\${SERVER_NAME}|${SERVER_NAME}|" /etc/nginx/conf.d/default.conf sed -i "s|\${SERVER_REDIRECT_CODE}|${SERVER_REDIRECT_CODE}|" /etc/nginx/conf.d/default.conf sed -i "s|\${SERVER_REDIRECT_PATH}|${SERVER_REDIRECT_PATH}|" /etc/nginx/conf.d/default.conf sed -i "s|\${SERVER_REDIRECT_SCHEME}|${SERVER_REDIRECT_SCHEME}|" /etc/nginx/conf.d/default.conf