Skip to content

Commit

Permalink
Merge pull request #5 from ixeft/master
Browse files Browse the repository at this point in the history
added possiblity to specify redirection code
  • Loading branch information
schmunk42 authored Jan 29, 2018
2 parents 4acdc20 + debbde5 commit 02a34b8
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 @@ -15,6 +15,8 @@ A very simple container to redirect HTTP traffic to another server, based on `ng
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
- `SERVER_REDIRECT_CODE` - optionally define the http code to use for redirection
if not set nginx 301 - is used

See also `docker-compose.yml` file.

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 ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH};
return ${SERVER_REDIRECT_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH};

# redirect server error pages to the static page /50x.html
#
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 redirect code from optional ENV var
if [ "$SERVER_REDIRECT_CODE" != '302' ] ; then
SERVER_REDIRECT_CODE='301'
fi

# set redirect path from optional ENV var
if [ ! -n "$SERVER_REDIRECT_PATH" ] ; then
SERVER_REDIRECT_PATH='$request_uri'
Expand All @@ -16,6 +21,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_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 02a34b8

Please sign in to comment.