diff --git a/Makefile b/Makefile index a34f7fd2a0e8d4874cfcd2b3893c5718779da935..dd8d4297070b300aee15b9a78206cce68004e00e 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 9a9de4192fb1f5cdd7d58913491e5903e14194e2..caabe0cd55a671c65b041667afeb3e4fef55ddc7 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 0000000000000000000000000000000000000000..dece20cd4fdd080b492935dbf81948db757fc367 --- /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 a88b0f3ed58e172fd1f75360ba6b11a441216375..50dc33041177a7e4755ec8c6db280ffbf075b5d3 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;