Skip to content

Commit 02a34b8

Browse files
authored
Merge pull request #5 from ixeft/master
added possiblity to specify redirection code
2 parents 4acdc20 + debbde5 commit 02a34b8

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ A very simple container to redirect HTTP traffic to another server, based on `ng
1515
if not set nginx var `$request_uri` is used
1616
- `SERVER_REDIRECT_SCHEME` - optionally define scheme to redirect to
1717
if not set nginx var `$scheme` is used
18+
- `SERVER_REDIRECT_CODE` - optionally define the http code to use for redirection
19+
if not set nginx 301 - is used
1820

1921
See also `docker-compose.yml` file.
2022

default.conf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ server {
22
listen 80;
33
server_name localhost;
44

5-
return 301 ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH};
5+
return ${SERVER_REDIRECT_CODE} ${SERVER_REDIRECT_SCHEME}://${SERVER_REDIRECT}${SERVER_REDIRECT_PATH};
66

77
# redirect server error pages to the static page /50x.html
88
#

run.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ if [ ! -n "$SERVER_REDIRECT" ] ; then
55
exit 1
66
fi
77

8+
# set redirect code from optional ENV var
9+
if [ "$SERVER_REDIRECT_CODE" != '302' ] ; then
10+
SERVER_REDIRECT_CODE='301'
11+
fi
12+
813
# set redirect path from optional ENV var
914
if [ ! -n "$SERVER_REDIRECT_PATH" ] ; then
1015
SERVER_REDIRECT_PATH='$request_uri'
@@ -16,6 +21,7 @@ if [ ! -n "$SERVER_REDIRECT_SCHEME" ] ; then
1621
fi
1722

1823
sed -i "s|\${SERVER_REDIRECT}|${SERVER_REDIRECT}|" /etc/nginx/conf.d/default.conf
24+
sed -i "s|\${SERVER_REDIRECT_CODE}|${SERVER_REDIRECT_CODE}|" /etc/nginx/conf.d/default.conf
1925
sed -i "s|\${SERVER_REDIRECT_PATH}|${SERVER_REDIRECT_PATH}|" /etc/nginx/conf.d/default.conf
2026
sed -i "s|\${SERVER_REDIRECT_SCHEME}|${SERVER_REDIRECT_SCHEME}|" /etc/nginx/conf.d/default.conf
2127

0 commit comments

Comments
 (0)