refactor REDIRECT_PROTO and add some examples

master
Michael Contento 7 years ago
parent b6c804b68c
commit 023f04c7a4

@ -35,7 +35,7 @@ ENV REDIRECT_CODE=302
# And the protocol we should redirect to. Change this to "https" if you
# serve via https (e.g. with a SSL-termination proxy infront of this)
ENV REDIRECT_SCHEME="http"
ENV REDIRECT_PROTO="auto"
ADD etc/ /etc/
ADD usr/ /usr/

@ -1,5 +0,0 @@
server {
listen 80;
server_name ~^(?!www.)(?<domain>.+)$;
return {{REDIRECT_CODE}} {{REDIRECT_SCHEME}}://www.$domain$request_uri;
}

@ -0,0 +1,6 @@
server {
listen 80;
server_name ~^(?!www.)(?<domain>.+)$;
return {{REDIRECT_CODE}} {{REDIRECT_PROTO}}://www.$domain$request_uri;
}

@ -1,5 +0,0 @@
server {
listen 80;
server_name ~^www.(?<domain>.+)$;
return {{REDIRECT_CODE}} {{REDIRECT_SCHEME}}://$domain$request_uri;
}

@ -0,0 +1,5 @@
server {
listen 80;
server_name ~^www.(?<domain>.+)$;
return {{REDIRECT_CODE}} {{REDIRECT_PROTO}}://$domain$request_uri;
}

@ -0,0 +1,7 @@
https://* {
errors stderr
tls self_signed
proxy / http://backend:80 {
transparent
}
}

@ -0,0 +1,13 @@
version: '3'
services:
backend:
build: ../../
volumes:
- './index.php:/var/www/index.php'
frontend:
image: abiosoft/caddy
volumes:
- './Caddyfile:/etc/Caddyfile'
ports:
- '443:443'

@ -0,0 +1,8 @@
version: '3'
services:
backend:
build: ../../
volumes:
- './index.php:/var/www/index.php'
ports:
- '80:80'

@ -0,0 +1,3 @@
<?php
phpinfo();

@ -1,25 +1,31 @@
#!/usr/bin/env sh
set -eu
chown www-data.www-data "${DOCUMENT_ROOT}"
# Properly detect requested redirect
if [ "${REDIRECT_PROTO}" == "auto" ]; then
REDIRECT_PROTO="\$http_x_forwarded_proto";
elif [ "${REDIRECT_PROTO}" != "http" ] && [ "${REDIRECT_PROTO}" != "https" ]; then
echo "ERROR: Invalid value for REDIRECT_PROTO, got '${REDIRECT_PROTO}'" >&2
echo "ERROR: Valid values are: 'auto', 'http' or 'https'" >&2
exit 1
fi
for file in /etc/nginx/*/*.conf; do
sed -i \
-e "s#{{REDIRECT_CODE}}#${REDIRECT_CODE}#g" \
# Replace templates in nginx config
for file in /etc/nginx/*/*.tpl; do
sed \
-e "s#{{DOCUMENT_ROOT}}#${DOCUMENT_ROOT}#g" \
-e "s#{{REDIRECT_SCHEME}}#${REDIRECT_SCHEME}#g" \
"${file}"
-e "s#{{REDIRECT_CODE}}#${REDIRECT_CODE}#g" \
-e "s#{{REDIRECT_PROTO}}#${REDIRECT_PROTO}#g" \
"${file}" \
> "${file%.tpl}"
done
# Activate the right
rm -f /etc/nginx/sites-enabled/redirect-*.conf
if [[ "${REDIRECT_MODE}" == "apex-to-www" ]]; then
ln -s \
/etc/nginx/sites-available/redirect-apex-to-www.conf \
/etc/nginx/sites-enabled/redirect-apex-to-www.conf
elif [[ "${REDIRECT_MODE}" == "www-to-apex" ]]; then
if [[ -f "/etc/nginx/sites-available/redirect-${REDIRECT_MODE}.conf" ]]; then
ln -s \
/etc/nginx/sites-available/redirect-www-to-apex.conf \
/etc/nginx/sites-enabled/redirect-www-to-apex.conf
"/etc/nginx/sites-available/redirect-${REDIRECT_MODE}.conf" \
"/etc/nginx/sites-enabled/redirect-${REDIRECT_MODE}.conf"
fi
exec /usr/bin/supervisord
exec /usr/bin/supervisord -c /etc/supervisord.conf

Loading…
Cancel
Save