From 31626242888724380b35bc8db3141de0d517f7be Mon Sep 17 00:00:00 2001
From: Pavel Kirilin <win10@list.ru>
Date: Fri, 10 Apr 2020 13:39:33 +0400
Subject: [PATCH] Updated Makefile. Description: - Added proto to add option
 for local runs. - Added http and https templates.

Signed-off-by: Pavel Kirilin <win10@list.ru>
---
 Makefile                                      | 12 ++++++++++--
 docker-compose.yml                            |  1 +
 nginx/subdomain_template_http.conf            | 19 +++++++++++++++++++
 ...ate.conf => subdomain_template_https.conf} |  3 ++-
 4 files changed, 32 insertions(+), 3 deletions(-)
 create mode 100644 nginx/subdomain_template_http.conf
 rename nginx/{subdomain_template.conf => subdomain_template_https.conf} (99%)

diff --git a/Makefile b/Makefile
index a34f7fd..dd8d429 100644
--- a/Makefile
+++ b/Makefile
@@ -62,7 +62,8 @@ shell:
 # 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.
-## Generate new subdomain configuration in nginx sites-available. with subdomain pointing to target. | parameters: target, subdomain
+#- protocol - default https.
+## Generate new subdomain configuration in nginx sites-available. with subdomain pointing to target. | parameters: target, subdomain, no_cert, proto
 add:
 ifndef addr
 	@echo "${RED}Error${RESET}: please specify ${YELLOW}addr${RESET} variable."
@@ -71,6 +72,9 @@ endif
 ifndef target
 	@echo "${RED}Error${RESET}: please specify ${YELLOW}target${RESET} variable"
 	exit 1
+endif
+ifndef proto
+	$(eval proto=https)
 endif
 	@set -e ;\
 	SUBDOMAIN_VAR=$$(echo "${addr}" | cut -d '.' -f1) ;\
@@ -78,7 +82,11 @@ endif
 	ZONE_VAR=$$(echo "${addr}" | cut -d '.' -f3);\
 	ZONE_VAR="$${ZONE_VAR:-com}";\
 	echo "Creating $${SUBDOMAIN_VAR}.$${DOMAIN_VAR} file"; \
-	cp ./nginx/subdomain_template.conf "./nginx/sites-enabled/$${SUBDOMAIN_VAR}.$${DOMAIN_VAR}.conf";\
+	if [[ "${proto}" == "https" ]];then \
+		cp ./nginx/subdomain_template_https.conf "./nginx/sites-enabled/$${SUBDOMAIN_VAR}.$${DOMAIN_VAR}.conf";\
+	else \
+		cp ./nginx/subdomain_template_http.conf "./nginx/sites-enabled/$${SUBDOMAIN_VAR}.$${DOMAIN_VAR}.conf";\
+	fi; \
 	sed -i "s/\$${sub_domain}/$${SUBDOMAIN_VAR}/g;"\
 	"s/\$${main_domain}/$${DOMAIN_VAR}/g;"\
 	"s/\$${domain_zone}/$${ZONE_VAR}/g;"\
diff --git a/docker-compose.yml b/docker-compose.yml
index 9a9de41..caabe0c 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -8,6 +8,7 @@ services:
   nginx:
     build: .
     container_name: memes_nginx
+    restart: always
     ports:
       - 80:80
       - 443:443
diff --git a/nginx/subdomain_template_http.conf b/nginx/subdomain_template_http.conf
new file mode 100644
index 0000000..dece20c
--- /dev/null
+++ b/nginx/subdomain_template_http.conf
@@ -0,0 +1,19 @@
+server{
+  
+  listen 80;
+  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;
+
+  location / {
+    resolver 127.0.0.11 valid=30s;
+    set $target ${target_cont};
+    proxy_pass  http://${target};
+    include /var/nginx/common/common_location.conf;
+    sub_filter /${sub_domain}/  /;
+  }
+}
diff --git a/nginx/subdomain_template.conf b/nginx/subdomain_template_https.conf
similarity index 99%
rename from nginx/subdomain_template.conf
rename to nginx/subdomain_template_https.conf
index a88b0f3..50dc330 100644
--- a/nginx/subdomain_template.conf
+++ b/nginx/subdomain_template_https.conf
@@ -1,10 +1,11 @@
 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;
 
-- 
GitLab