Skip to content

Commit ac2910a

Browse files
authored
Merge pull request #1086 from linuxserver/swag-auto-proxy-custom-location
add support for swag_location_custom_directive
2 parents 5163bc8 + d4613b9 commit ac2910a

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ This mod gives SWAG the ability to auto-detect running containers via labels and
1717
- `swag_auth=authelia` - *optional* - enables auth methods (options are `authelia`, `authentik`, `ldap`, `tinyauth` and `http` for basic http auth)
1818
- `swag_auth_bypass=/api,/othersubfolder` - *optional* - bypasses auth for selected subfolders. Comma separated, no spaces.
1919
- `swag_server_custom_directive=custom_directive;` - *optional* - injects the label value as is into the server block of the generated conf. Must be a valid nginx directive, ending with a semi colon.
20+
- `swag_location_custom_directive=custom_directive;` - *optional* - injects the label value as is into each location block of the generated conf. Must be a valid nginx directive, ending with a semi colon.
2021
- `swag_preset_conf=confname` - *optional* - allows defining a preset conf to use if the container name does not match one (if the conf name is `radarr.subdomain.conf.sample`, set this value to `radarr`). If the container name matches an existing conf, this var will be ignored.
2122

2223

root/app/auto-proxy.sh

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ else
1313
AUTO_GEN="${CONTAINER} ${AUTO_GEN}"
1414
else
1515
INSPECTION=$(docker inspect ${CONTAINER})
16-
for VAR in swag_address swag_port swag_proto swag_url swag_auth swag_auth_bypass swag_server_custom_directive swag_preset_conf; do
16+
for VAR in swag_address swag_port swag_proto swag_url swag_auth swag_auth_bypass swag_server_custom_directive swag_location_custom_directive swag_preset_conf; do
1717
VAR_VALUE=$(echo ${INSPECTION} | jq -r ".[0].Config.Labels[\"${VAR}\"]")
1818
if [ "${VAR_VALUE}" == "null" ]; then
1919
VAR_VALUE=""
@@ -40,7 +40,7 @@ fi
4040
for CONTAINER in ${AUTO_GEN}; do
4141
INSPECTION=$(docker inspect ${CONTAINER})
4242
rm -rf "/auto-proxy/${CONTAINER}.conf"
43-
for VAR in swag_address swag_port swag_proto swag_url swag_auth swag_auth_bypass swag_server_custom_directive swag_preset_conf; do
43+
for VAR in swag_address swag_port swag_proto swag_url swag_auth swag_auth_bypass swag_server_custom_directive swag_location_custom_directive swag_preset_conf; do
4444
VAR_VALUE=$(echo ${INSPECTION} | jq -r ".[0].Config.Labels[\"${VAR}\"]")
4545
if [ "${VAR_VALUE}" == "null" ]; then
4646
VAR_VALUE=""
@@ -87,6 +87,11 @@ for CONTAINER in ${AUTO_GEN}; do
8787
sed -i -e '/include.*ssl.conf;/a\' -e " ${SED_swag_server_custom_directive}" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
8888
echo "**** Adding custom directive from the swag_server_custom_directive label for ${CONTAINER} ****"
8989
fi
90+
if [ -n "${swag_location_custom_directive}" ]; then
91+
SED_swag_location_custom_directive=$(sed -e 's/[&\\|]/\\&/g; s|$|\\|; $s|\\$||' <<<"${swag_location_custom_directive}")
92+
sed -i -e '/^[[:space:]]*proxy_pass.*;/a\' -e " ${SED_swag_location_custom_directive}" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
93+
echo "**** Adding custom directive from the swag_location_custom_directive label for ${CONTAINER} ****"
94+
fi
9095
if [ "${swag_auth}" == "authelia" ]; then
9196
sed -i "s|#include /config/nginx/authelia|include /config/nginx/authelia|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
9297
echo "**** Enabling Authelia for ${CONTAINER} ****"
@@ -164,6 +169,11 @@ DUDE
164169
sed -i -e '/include.*ssl.conf;/a\' -e " ${SED_swag_server_custom_directive}" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
165170
echo "**** Adding custom directive from the swag_server_custom_directive label for ${CONTAINER} ****"
166171
fi
172+
if [ -n "${swag_location_custom_directive}" ]; then
173+
SED_swag_location_custom_directive=$(sed -e 's/[&\\|]/\\&/g; s|$|\\|; $s|\\$||' <<<"${swag_location_custom_directive}")
174+
sed -i -e '/^[[:space:]]*proxy_pass.*;/a\' -e " ${SED_swag_location_custom_directive}" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
175+
echo "**** Adding custom directive from the swag_location_custom_directive label for ${CONTAINER} ****"
176+
fi
167177
if [ "${swag_auth}" == "authelia" ]; then
168178
sed -i "s|#include /config/nginx/authelia|include /config/nginx/authelia|g" "/etc/nginx/http.d/auto-proxy-${CONTAINER}.subdomain.conf"
169179
echo "**** Enabling Authelia for ${CONTAINER} ****"

0 commit comments

Comments
 (0)