refactor REDIRECT_PROTO and add some examples
This commit is contained in:
parent
b6c804b68c
commit
023f04c7a4
12 changed files with 72 additions and 31 deletions
|
@ -35,7 +35,7 @@ ENV REDIRECT_CODE=302
|
||||||
|
|
||||||
# And the protocol we should redirect to. Change this to "https" if you
|
# 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)
|
# 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 etc/ /etc/
|
||||||
ADD usr/ /usr/
|
ADD usr/ /usr/
|
||||||
|
|
|
@ -1,5 +0,0 @@
|
||||||
server {
|
|
||||||
listen 80;
|
|
||||||
server_name ~^(?!www.)(?<domain>.+)$;
|
|
||||||
return {{REDIRECT_CODE}} {{REDIRECT_SCHEME}}://www.$domain$request_uri;
|
|
||||||
}
|
|
6
etc/nginx/sites-available/redirect-apex-to-www.conf.tpl
Normal file
6
etc/nginx/sites-available/redirect-apex-to-www.conf.tpl
Normal file
|
@ -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;
|
|
||||||
}
|
|
5
etc/nginx/sites-available/redirect-www-to-apex.conf.tpl
Normal file
5
etc/nginx/sites-available/redirect-www-to-apex.conf.tpl
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
server {
|
||||||
|
listen 80;
|
||||||
|
server_name ~^www.(?<domain>.+)$;
|
||||||
|
return {{REDIRECT_CODE}} {{REDIRECT_PROTO}}://$domain$request_uri;
|
||||||
|
}
|
7
examples/phpinfo-behind-https/Caddyfile
Normal file
7
examples/phpinfo-behind-https/Caddyfile
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
https://* {
|
||||||
|
errors stderr
|
||||||
|
tls self_signed
|
||||||
|
proxy / http://backend:80 {
|
||||||
|
transparent
|
||||||
|
}
|
||||||
|
}
|
13
examples/phpinfo-behind-https/docker-compose.yml
Normal file
13
examples/phpinfo-behind-https/docker-compose.yml
Normal file
|
@ -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'
|
3
examples/phpinfo-behind-https/index.php
Normal file
3
examples/phpinfo-behind-https/index.php
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
phpinfo();
|
8
examples/phpinfo/docker-compose.yml
Normal file
8
examples/phpinfo/docker-compose.yml
Normal file
|
@ -0,0 +1,8 @@
|
||||||
|
version: '3'
|
||||||
|
services:
|
||||||
|
backend:
|
||||||
|
build: ../../
|
||||||
|
volumes:
|
||||||
|
- './index.php:/var/www/index.php'
|
||||||
|
ports:
|
||||||
|
- '80:80'
|
3
examples/phpinfo/index.php
Normal file
3
examples/phpinfo/index.php
Normal file
|
@ -0,0 +1,3 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
phpinfo();
|
|
@ -1,25 +1,31 @@
|
||||||
#!/usr/bin/env sh
|
#!/usr/bin/env sh
|
||||||
set -eu
|
set -eu
|
||||||
|
|
||||||
chown www-data.www-data "${DOCUMENT_ROOT}"
|
# Properly detect requested redirect
|
||||||
|
if [ "${REDIRECT_PROTO}" == "auto" ]; then
|
||||||
for file in /etc/nginx/*/*.conf; do
|
REDIRECT_PROTO="\$http_x_forwarded_proto";
|
||||||
sed -i \
|
elif [ "${REDIRECT_PROTO}" != "http" ] && [ "${REDIRECT_PROTO}" != "https" ]; then
|
||||||
-e "s#{{REDIRECT_CODE}}#${REDIRECT_CODE}#g" \
|
echo "ERROR: Invalid value for REDIRECT_PROTO, got '${REDIRECT_PROTO}'" >&2
|
||||||
-e "s#{{DOCUMENT_ROOT}}#${DOCUMENT_ROOT}#g" \
|
echo "ERROR: Valid values are: 'auto', 'http' or 'https'" >&2
|
||||||
-e "s#{{REDIRECT_SCHEME}}#${REDIRECT_SCHEME}#g" \
|
exit 1
|
||||||
"${file}"
|
|
||||||
done
|
|
||||||
|
|
||||||
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
|
|
||||||
ln -s \
|
|
||||||
/etc/nginx/sites-available/redirect-www-to-apex.conf \
|
|
||||||
/etc/nginx/sites-enabled/redirect-www-to-apex.conf
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
exec /usr/bin/supervisord
|
# Replace templates in nginx config
|
||||||
|
for file in /etc/nginx/*/*.tpl; do
|
||||||
|
sed \
|
||||||
|
-e "s#{{DOCUMENT_ROOT}}#${DOCUMENT_ROOT}#g" \
|
||||||
|
-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 [[ -f "/etc/nginx/sites-available/redirect-${REDIRECT_MODE}.conf" ]]; then
|
||||||
|
ln -s \
|
||||||
|
"/etc/nginx/sites-available/redirect-${REDIRECT_MODE}.conf" \
|
||||||
|
"/etc/nginx/sites-enabled/redirect-${REDIRECT_MODE}.conf"
|
||||||
|
fi
|
||||||
|
|
||||||
|
exec /usr/bin/supervisord -c /etc/supervisord.conf
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue