deployment: Add volume to configure custom locations in nginx. This is useful to add reverse proxy or other services to the nginx configuration to default HTTPS_PORT configured

pull/660/head
cruizba 2021-09-30 16:33:08 +02:00
parent 197ddc8ce8
commit 110878f4c9
8 changed files with 54 additions and 0 deletions

View File

@ -103,6 +103,7 @@ services:
- ./certificates:/etc/letsencrypt - ./certificates:/etc/letsencrypt
- ./owncert:/owncert - ./owncert:/owncert
- ./custom-nginx-vhosts:/etc/nginx/vhost.d/ - ./custom-nginx-vhosts:/etc/nginx/vhost.d/
- ./custom-nginx-locations:/custom-nginx-locations
- ${OPENVIDU_RECORDING_CUSTOM_LAYOUT}:/opt/openvidu/custom-layout - ${OPENVIDU_RECORDING_CUSTOM_LAYOUT}:/opt/openvidu/custom-layout
environment: environment:
- DOMAIN_OR_PUBLIC_IP=${DOMAIN_OR_PUBLIC_IP} - DOMAIN_OR_PUBLIC_IP=${DOMAIN_OR_PUBLIC_IP}

View File

@ -60,6 +60,10 @@ new_ov_installation() {
printf "\n => Creating folder 'custom-nginx-vhosts'..." printf "\n => Creating folder 'custom-nginx-vhosts'..."
mkdir "${OPENVIDU_FOLDER}/custom-nginx-vhosts" || fatal_error "Error while creating the folder 'custom-nginx-vhosts'" mkdir "${OPENVIDU_FOLDER}/custom-nginx-vhosts" || fatal_error "Error while creating the folder 'custom-nginx-vhosts'"
# Create vhost nginx folder
printf "\n => Creating folder 'custom-nginx-locations'..."
mkdir "${OPENVIDU_FOLDER}/custom-nginx-locations" || fatal_error "Error while creating the folder 'custom-nginx-locations'"
# Ready to use # Ready to use
printf '\n' printf '\n'
printf '\n' printf '\n'
@ -200,6 +204,11 @@ upgrade_ov() {
printf '\n - custom-nginx-vhosts' printf '\n - custom-nginx-vhosts'
fi fi
if [ -d "${OPENVIDU_PREVIOUS_FOLDER}/custom-nginx-locations" ]; then
mv "${OPENVIDU_PREVIOUS_FOLDER}/custom-nginx-locations" "${ROLL_BACK_FOLDER}" || fatal_error "Error while moving previous directory 'custom-nginx-locations'"
printf '\n - custom-nginx-locations'
fi
# Move tmp files to Openvidu # Move tmp files to Openvidu
printf '\n => Updating files:' printf '\n => Updating files:'

View File

@ -109,6 +109,10 @@ new_ov_installation() {
printf "\n => Creating folder 'custom-nginx-vhosts'..." printf "\n => Creating folder 'custom-nginx-vhosts'..."
mkdir "${OPENVIDU_FOLDER}/custom-nginx-vhosts" || fatal_error "Error while creating the folder 'custom-nginx-vhosts'" mkdir "${OPENVIDU_FOLDER}/custom-nginx-vhosts" || fatal_error "Error while creating the folder 'custom-nginx-vhosts'"
# Create vhost nginx folder
printf "\n => Creating folder 'custom-nginx-locations'..."
mkdir "${OPENVIDU_FOLDER}/custom-nginx-locations" || fatal_error "Error while creating the folder 'custom-nginx-locations'"
# Ready to use # Ready to use
printf '\n' printf '\n'
printf '\n' printf '\n'
@ -291,6 +295,11 @@ upgrade_ov() {
printf '\n - custom-nginx-vhosts' printf '\n - custom-nginx-vhosts'
fi fi
if [ -d "${OPENVIDU_PREVIOUS_FOLDER}/custom-nginx-locations" ]; then
mv "${OPENVIDU_PREVIOUS_FOLDER}/custom-nginx-locations" "${ROLL_BACK_FOLDER}" || fatal_error "Error while moving previous directory 'custom-nginx-locations'"
printf '\n - custom-nginx-locations'
fi
# Move tmp files to Openvidu # Move tmp files to Openvidu
printf '\n => Updating files:' printf '\n => Updating files:'

View File

@ -93,6 +93,7 @@ services:
- ./certificates:/etc/letsencrypt - ./certificates:/etc/letsencrypt
- ./owncert:/owncert - ./owncert:/owncert
- ./custom-nginx-vhosts:/etc/nginx/vhost.d/ - ./custom-nginx-vhosts:/etc/nginx/vhost.d/
- ./custom-nginx-locations:/custom-nginx-locations
- ${OPENVIDU_RECORDING_CUSTOM_LAYOUT}:/opt/openvidu/custom-layout - ${OPENVIDU_RECORDING_CUSTOM_LAYOUT}:/opt/openvidu/custom-layout
environment: environment:
- DOMAIN_OR_PUBLIC_IP=${DOMAIN_OR_PUBLIC_IP} - DOMAIN_OR_PUBLIC_IP=${DOMAIN_OR_PUBLIC_IP}

View File

@ -109,6 +109,10 @@ new_ov_installation() {
printf "\n => Creating folder 'custom-nginx-vhosts'..." printf "\n => Creating folder 'custom-nginx-vhosts'..."
mkdir "${OPENVIDU_FOLDER}/custom-nginx-vhosts" || fatal_error "Error while creating the folder 'custom-nginx-vhosts'" mkdir "${OPENVIDU_FOLDER}/custom-nginx-vhosts" || fatal_error "Error while creating the folder 'custom-nginx-vhosts'"
# Create vhost nginx folder
printf "\n => Creating folder 'custom-nginx-locations'..."
mkdir "${OPENVIDU_FOLDER}/custom-nginx-locations" || fatal_error "Error while creating the folder 'custom-nginx-locations'"
# Ready to use # Ready to use
printf '\n' printf '\n'
printf '\n' printf '\n'
@ -291,6 +295,11 @@ upgrade_ov() {
printf '\n - custom-nginx-vhosts' printf '\n - custom-nginx-vhosts'
fi fi
if [ -d "${OPENVIDU_PREVIOUS_FOLDER}/custom-nginx-locations" ]; then
mv "${OPENVIDU_PREVIOUS_FOLDER}/custom-nginx-locations" "${ROLL_BACK_FOLDER}" || fatal_error "Error while moving previous directory 'custom-nginx-locations'"
printf '\n - custom-nginx-locations'
fi
# Move tmp files to Openvidu # Move tmp files to Openvidu
printf '\n => Updating files:' printf '\n => Updating files:'

View File

@ -55,4 +55,6 @@ server {
root /var/www/certbot; root /var/www/certbot;
try_files $uri $uri/ =404; try_files $uri $uri/ =404;
} }
{custom_locations}
} }

View File

@ -80,4 +80,6 @@ server {
root /var/www/certbot; root /var/www/certbot;
try_files $uri $uri/ =404; try_files $uri $uri/ =404;
} }
{custom_locations}
} }

View File

@ -262,6 +262,27 @@ sed -e '/{ssl_config}/{r default_nginx_conf/global/ssl_config.conf' -e 'd}' -i /
sed -e '/{proxy_config}/{r default_nginx_conf/global/proxy_config.conf' -e 'd}' -i /etc/nginx/conf.d/* sed -e '/{proxy_config}/{r default_nginx_conf/global/proxy_config.conf' -e 'd}' -i /etc/nginx/conf.d/*
sed -i "s/{domain_name}/${DOMAIN_OR_PUBLIC_IP}/g" /etc/nginx/conf.d/* sed -i "s/{domain_name}/${DOMAIN_OR_PUBLIC_IP}/g" /etc/nginx/conf.d/*
# Read custom locations and apply them in configuration
if [[ -d /custom-nginx-locations ]]; then
TMP_PARSED_CUSTOM_LOCATIONS="$(mktemp)"
{
for CUSTOM_LOCATION in /custom-nginx-locations/*.conf; do
[ -f "${CUSTOM_LOCATION}" ] || break
echo " # Custom location loaded from: ${CUSTOM_LOCATION}"
while read -r ; do
echo " ${REPLY}"
done < "${CUSTOM_LOCATION}"
echo
done
} > "${TMP_PARSED_CUSTOM_LOCATIONS}"
if [[ -n $(cat "${TMP_PARSED_CUSTOM_LOCATIONS}") ]]; then
sed -e "/{custom_locations}/{r ${TMP_PARSED_CUSTOM_LOCATIONS}" -e 'd}' -i /etc/nginx/conf.d/*
fi
rm "${TMP_PARSED_CUSTOM_LOCATIONS}"
fi
# Delete custom_locations if not replaced
sed -i '/{custom_locations}/d' /etc/nginx/conf.d/*
# IPv6 listening (RFC 6540) # IPv6 listening (RFC 6540)
if [ ! -f /proc/net/if_inet6 ]; then if [ ! -f /proc/net/if_inet6 ]; then
sed -i '/\[::\]:{http_port}/d' /etc/nginx/conf.d/* sed -i '/\[::\]:{http_port}/d' /etc/nginx/conf.d/*