Skip to content

Commit

Permalink
Merge pull request #7 from claflico/master
Browse files Browse the repository at this point in the history
Add SERVER_NAME variable
  • Loading branch information
schmunk42 authored Mar 28, 2018
2 parents bd998ed + ea5a658 commit af69434
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.(?<subdomain>.+).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
Expand Down
2 changes: 1 addition & 1 deletion default.conf
Original file line number Diff line number Diff line change
@@ -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};

Expand Down
6 changes: 6 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand Down

0 comments on commit af69434

Please sign in to comment.