diff --git a/Makefile b/Makefile index dd8d4297070b300aee15b9a78206cce68004e00e..c16c1efe1715b12b78bdccc8da4cbc364ac94048 100644 --- a/Makefile +++ b/Makefile @@ -59,6 +59,11 @@ reload: shell: @docker exec -it ${cont_name} sh +## Show all hosted domains and their targets. +list: + @chmod 777 ./listing.sh + @sh ./listing.sh + # params: #- target - proxy destanation adress. Also you can specify container name in memes_network; #- addr - new address mapping in format ${subdomain}.${domain}.${zone} e.g. sub.domain.com. @@ -80,21 +85,24 @@ endif SUBDOMAIN_VAR=$$(echo "${addr}" | cut -d '.' -f1) ;\ DOMAIN_VAR=$$(echo "${addr}" | cut -d '.' -f2);\ ZONE_VAR=$$(echo "${addr}" | cut -d '.' -f3);\ - ZONE_VAR="$${ZONE_VAR:-com}";\ - echo "Creating $${SUBDOMAIN_VAR}.$${DOMAIN_VAR} file"; \ + if [[ -n "$${ZONE_VAR}" ]];then \ + ZONE_VAR=".$${ZONE_VAR}"; \ + fi; \ + CONF_FILE="./nginx/sites-enabled/$${SUBDOMAIN_VAR}.$${DOMAIN_VAR}$${ZONE_VAR}.conf";\ + echo "Creating config file '$${CONF_FILE}'"; \ if [[ "${proto}" == "https" ]];then \ - cp ./nginx/subdomain_template_https.conf "./nginx/sites-enabled/$${SUBDOMAIN_VAR}.$${DOMAIN_VAR}.conf";\ + cp ./nginx/subdomain_template_https.conf "$${CONF_FILE}";\ else \ - cp ./nginx/subdomain_template_http.conf "./nginx/sites-enabled/$${SUBDOMAIN_VAR}.$${DOMAIN_VAR}.conf";\ + cp ./nginx/subdomain_template_http.conf "$${CONF_FILE}";\ fi; \ sed -i "s/\$${sub_domain}/$${SUBDOMAIN_VAR}/g;"\ "s/\$${main_domain}/$${DOMAIN_VAR}/g;"\ "s/\$${domain_zone}/$${ZONE_VAR}/g;"\ - "s/\$${target_cont}/${target}/" "./nginx/sites-enabled/$${SUBDOMAIN_VAR}.$${DOMAIN_VAR}.conf"; \ + "s/\$${target_cont}/${target}/" "$${CONF_FILE}"; \ docker exec -it ${cont_name} nginx -s reload; if [ $$? -ne 0 ]; then\ echo -e '${RED}Wrong config.${RESET}\n'\ 'Please make sure that ${YELLOW}target${RESET} and ${YELLOW}addr${RESET} parameters was provided and correct.' ;\ - rm ./nginx/sites-enabled/$${SUBDOMAIN_VAR}.$${DOMAIN_VAR}.conf ;\ + rm "$${CONF_FILE}" ;\ docker exec -it ${cont_name} nginx -s reload;\ fi diff --git a/listing.sh b/listing.sh new file mode 100755 index 0000000000000000000000000000000000000000..c2add5e29addc76e0f2258b45eecde61dbbb2d29 --- /dev/null +++ b/listing.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +RESET="$(tput -Txterm sgr0)" +RED="$(tput -Txterm setaf 1)" +GREEN="$(tput -Txterm setaf 2)" +YELLOW="$(tput -Txterm setaf 3)" + +sites_dir="./nginx/sites-enabled/" + +get_param(){ + grep "$1" "${sites_dir}${filename}" | xargs | cut -d ' ' -f "$2" | sed 's/;//' +} + + +for filename in $(ls "$sites_dir" | sort -d); do + listen_to="$(get_param listen 2)" + PROTO="https" + if [ 80 = "$listen_to" ]; then + PROTO="http" + fi + ADDR="$(get_param server_name 2)" + if [ "$ADDR" = "_" ];then + continue; + fi + STATUS="${GREEN}[ UP ]" + URL="$PROTO://${ADDR}" + STATUS_CODE="$(curl -o /dev/null -s -w "%{http_code}\n" "$URL")" + if [ "$STATUS_CODE" -ne "200" ];then + STATUS="${RED}[ DOWN ]" + fi + PROXY="$(get_param "set \$target" 3)" + echo "$STATUS ${URL}${RESET} => ${YELLOW}${PROXY}${RESET}"; +done diff --git a/nginx/subdomain_template_http.conf b/nginx/subdomain_template_http.conf index dece20cd4fdd080b492935dbf81948db757fc367..b58b8a71dda68a2c4e8e0f337a5c8162009e7d83 100644 --- a/nginx/subdomain_template_http.conf +++ b/nginx/subdomain_template_http.conf @@ -1,13 +1,13 @@ server{ listen 80; - server_name ${sub_domain}.${main_domain}.${domain_zone}; + server_name ${sub_domain}.${main_domain}${domain_zone}; include /var/nginx/common/server.conf; client_max_body_size 100m; - access_log /var/log/nginx/${sub_domain}.${main_domain}.${domain_zone}_access.log combined; - error_log /var/log/nginx/${sub_domain}.${main_domain}.${domain_zone}_error.log; + access_log /var/log/nginx/${sub_domain}.${main_domain}${domain_zone}_access.log combined; + error_log /var/log/nginx/${sub_domain}.${main_domain}${domain_zone}_error.log; location / { resolver 127.0.0.11 valid=30s; diff --git a/nginx/subdomain_template_https.conf b/nginx/subdomain_template_https.conf index 50dc33041177a7e4755ec8c6db280ffbf075b5d3..185f7e0786363195a2d16a1ceca4a5dd13e050e7 100644 --- a/nginx/subdomain_template_https.conf +++ b/nginx/subdomain_template_https.conf @@ -1,7 +1,7 @@ server{ listen 443 ssl; - server_name ${sub_domain}.${main_domain}.${domain_zone}; + server_name ${sub_domain}.${main_domain}${domain_zone}; ssl_certificate /var/nginx/ssl/${main_domain}_certificate.pem; ssl_certificate_key /var/nginx/ssl/${main_domain}_private.key; @@ -9,8 +9,8 @@ server{ include /var/nginx/common/server.conf; client_max_body_size 100m; - access_log /var/log/nginx/${sub_domain}.${main_domain}.${domain_zone}_access.log combined; - error_log /var/log/nginx/${sub_domain}.${main_domain}.${domain_zone}_error.log; + access_log /var/log/nginx/${sub_domain}.${main_domain}${domain_zone}_access.log combined; + error_log /var/log/nginx/${sub_domain}.${main_domain}${domain_zone}_error.log; location / { resolver 127.0.0.11 valid=30s;