From aab484b702f9f06384d2682d33b8c24c2a37bd77 Mon Sep 17 00:00:00 2001
From: Pavel Kirilin <win10@list.ru>
Date: Fri, 10 Apr 2020 01:50:28 +0400
Subject: [PATCH] Updated for multiple domain configuration.

Signed-off-by: Pavel Kirilin <win10@list.ru>
---
 Makefile                      | 39 +++++++++++++++++++++++++----------
 nginx/common/server.conf      |  4 ----
 nginx/subdomain_template.conf |  4 ++++
 3 files changed, 32 insertions(+), 15 deletions(-)

diff --git a/Makefile b/Makefile
index fc5f518..f0955ac 100644
--- a/Makefile
+++ b/Makefile
@@ -61,29 +61,46 @@ shell:
 
 # params:
 #- target - proxy destanation adress. Also you can specify container name in memes_network;
-#- subdomain - new subdomain name.
-## Generate new subdomain configuration in nginx sites-available. with subdomain pointing to target. | parameters: target, subdomain
+#- addr - new address mapping in format ${subdomain}.${domain}.
+#- zone - new address zone. Default: 'com'.
+## Generate new subdomain configuration in nginx sites-available. with subdomain pointing to target. | parameters: target, subdomain, zone
 add:
-ifndef subdomain
-	@echo "${RED}Error${RESET}: please specify ${YELLOW}subdomain${RESET} variable"
+ifndef addr
+	@echo "${RED}Error${RESET}: please specify ${YELLOW}addr${RESET} variable."
 	exit 1
 endif
 ifndef target
 	@echo "${RED}Error${RESET}: please specify ${YELLOW}target${RESET} variable"
 	exit 1
 endif
-	cp ./nginx/subdomain_template.conf ./nginx/sites-enabled/$(subdomain).$(domain_name).conf
-	sed -i 's/$${sub_domain}/${subdomain}/g;'\
-	's/\$${main_domain}/${domain_name}/g;'\
-	's/\$${domain_zone}/${domain_zone}/g;'\
-	's/$${target_cont}/${target}/' ./nginx/sites-enabled/$(subdomain).$(domain_name).conf
-	@docker exec -it ${cont_name} nginx -s reload; if [ $$? -ne 0 ]; then\
+ifndef zone
+	$(eval zone="com")
+endif
+	set -e ;\
+	SUBDOMAIN_VAR=$$(echo "${addr}" | cut -d '.' -f1) ;\
+	DOMAIN_VAR=$$(echo "${addr}" | cut -d '.' -f2);\
+	cp ./nginx/subdomain_template.conf "./nginx/sites-enabled/$${SUBDOMAIN_VAR}.$${DOMAIN_VAR}.conf";\
+	sed -i "s/\$${sub_domain}/$${SUBDOMAIN_VAR}/g;"\
+	"s/\$${main_domain}/$${DOMAIN_VAR}/g;"\
+	"s/\$${domain_zone}/${zone}/g;"\
+	"s/\$${target_cont}/${target}/" "./nginx/sites-enabled/$${SUBDOMAIN_VAR}.$${DOMAIN_VAR}.conf"; \
+	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}subdomain${RESET} parameters was provided and correct.' ;\
-		rm ./nginx/sites-enabled/$(subdomain).$(domain_name).conf ;\
+		rm ./nginx/sites-enabled/$${SUBDOMAIN_VAR}.$${DOMAIN_VAR}.conf ;\
 		docker exec -it ${cont_name} nginx -s reload;\
 	fi
 
+
+tesa:
+ifndef addr
+	$(eval addr="hui.sosi")
+endif
+	set -e ;\
+	TMP=$$(echo "${addr}" | cut -d '.' -f1) ;\
+	TMP2=$$(echo "${addr}" | cut -d '.' -f2);\
+	echo "$${TMP}____$${TMP2}";
+
 _create_trash:
 	mkdir -p ./trash
 
diff --git a/nginx/common/server.conf b/nginx/common/server.conf
index 091325f..70f84ab 100644
--- a/nginx/common/server.conf
+++ b/nginx/common/server.conf
@@ -1,6 +1,3 @@
-ssl_certificate /var/nginx/ssl/le-memese_certificate.pem;
-ssl_certificate_key /var/nginx/ssl/le-memese_private.key;
-
 charset utf-8;
 
 gzip on;
@@ -19,7 +16,6 @@ text/javascript
 application/json
 application/xml+rss;
 
-client_max_body_size            100m;
 client_body_buffer_size         128k;
 client_header_buffer_size       5120k;
 large_client_header_buffers 16  5120k;
diff --git a/nginx/subdomain_template.conf b/nginx/subdomain_template.conf
index 5a40b9a..a88b0f3 100644
--- a/nginx/subdomain_template.conf
+++ b/nginx/subdomain_template.conf
@@ -1,8 +1,12 @@
 server{
   listen 443 ssl;
   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;
   
   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;
-- 
GitLab