Skip to content

Commit

Permalink
Merge pull request #4 from martinvw/feature/add-configurable-scheme
Browse files Browse the repository at this point in the history
Added support for a configurable scheme
  • Loading branch information
schmunk42 authored Dec 28, 2017
2 parents 80b32ad + a88f85c commit 4acdc20
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 3 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ A very simple container to redirect HTTP traffic to another server, based on `ng
- `SERVER_REDIRECT` - server to redirect to, eg. `www.example.com`
- `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
if not set nginx var `$scheme` is used

See also `docker-compose.yml` file.

Expand All @@ -27,6 +28,7 @@ With `docker`

docker run -e SERVER_REDIRECT=www.example.com -p 8888:80 schmunk42/nginx-redirect
docker run -e SERVER_REDIRECT=www.example.com -e SERVER_REDIRECT_PATH=/landingpage -p 8888:80 schmunk42/nginx-redirect
docker run -e SERVER_REDIRECT=www.example.com -e SERVER_REDIRECT_PATH=/landingpage -e SERVER_REDIRECT_SCHEME=https -p 8888:80 schmunk42/nginx-redirect

---

Expand Down
2 changes: 1 addition & 1 deletion default.conf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ server {
listen 80;
server_name localhost;

return 301 $scheme://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH};
return 301 ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH};

# redirect server error pages to the static page /50x.html
#
Expand Down
5 changes: 4 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,8 @@ to:
environment:
- SERVER_REDIRECT=www.example.com
# optionally define path to redirect all requests
# if not set nginx var is used
# if not set nginx var $request_uri is used
#- SERVER_REDIRECT_PATH=/landingpage
# optionally define schema to redirect all requests
# if not set nginx var $scheme is used
#- SERVER_REDIRECT_SCHEME=https
6 changes: 6 additions & 0 deletions run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ if [ ! -n "$SERVER_REDIRECT_PATH" ] ; then
SERVER_REDIRECT_PATH='$request_uri'
fi

# set redirect scheme from optional ENV var
if [ ! -n "$SERVER_REDIRECT_SCHEME" ] ; then
SERVER_REDIRECT_SCHEME='$scheme'
fi

sed -i "s|\${SERVER_REDIRECT}|${SERVER_REDIRECT}|" /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

nginx -g 'daemon off;'

0 comments on commit 4acdc20

Please sign in to comment.