commit a60193de7a3aaead14f61a00bb271d2c7eda8f1e
Author: ballakt <ballakt@zcu.cz>
Date:   Sat May 23 17:34:48 2020 +0000

    Feature Re #7745 nginx configuration

diff --git a/.vscode/extensions.json b/.vscode/extensions.json
index e98a298..ea991f6 100644
--- a/.vscode/extensions.json
+++ b/.vscode/extensions.json
@@ -1,6 +1,11 @@
 {
     "recommendations": [
-        "ms-vscode-remote.remote-containers"
+        "ms-vscode-remote.remote-containers",
+        "vscode-icons-team.vscode-icons",
+        "ms-azuretools.vscode-docker",
+        "raynigon.nginx-formatter",
+        "mads-hartmann.bash-ide-vscode",
+        "shakram02.bash-beautify"
     ]
 
 }
\ No newline at end of file
diff --git a/.vscode/settings.json b/.vscode/settings.json
new file mode 100644
index 0000000..23fd35f
--- /dev/null
+++ b/.vscode/settings.json
@@ -0,0 +1,3 @@
+{
+    "editor.formatOnSave": true
+}
\ No newline at end of file
diff --git a/docker-compose-dev.yml b/docker-compose-dev.yml
index 10d1c7a..565edc1 100644
--- a/docker-compose-dev.yml
+++ b/docker-compose-dev.yml
@@ -12,6 +12,9 @@ services:
                volumes:
                         - data-db:/data/db
                         - ./dev-dump:/dev-dump
+       nginx: 
+               volumes: 
+                        - ./docker/nginx/sites-dev:/etc/nginx/sites-available
 volumes:
     data-db:
     vscode-extensions-php:
diff --git a/docker-compose-prod.yml b/docker-compose-prod.yml
index 24d3826..5ffa854 100644
--- a/docker-compose-prod.yml
+++ b/docker-compose-prod.yml
@@ -1,5 +1,11 @@
 version: "3.2"
 services:
        database:
-               volumes:
-                        - /database:/data/db
\ No newline at end of file
+                volumes:
+                         - /database:/data/db
+       nginx:
+              ports: 
+                     - "443:443"
+              volumes: 
+                     - /etc/letsencrypt:/root/.acme.sh/heatmap.zcu.cz
+                     - ./docker/nginx/sites-dev:/etc/nginx/sites-available
\ No newline at end of file
diff --git a/docker-compose.yml b/docker-compose.yml
index 39c5903..ebc6807 100644
--- a/docker-compose.yml
+++ b/docker-compose.yml
@@ -42,6 +42,8 @@ services:
                volumes:
                        - ./logs/nginx:/var/nginx/log
                        - ./website/:/var/www/symfony
+                       - ./docker/nginx/sites:/etc/nginx/sites-available
+
                container_name: "heatmap_nginx"
        database:
                image: 'mongo'
diff --git a/docker/nginx/Dockerfile b/docker/nginx/Dockerfile
index 1f8d147..c022dd9 100644
--- a/docker/nginx/Dockerfile
+++ b/docker/nginx/Dockerfile
@@ -1,6 +1,8 @@
 FROM nginx:alpine
 COPY nginx.conf /etc/nginx
 COPY conf.d /etc/nginx/conf.d
-ADD ./sites /etc/nginx/sites-available
+RUN apk add netcat-openbsd bc curl bash wget openssl; \
+    apk add libressl; \
+    wget -O -  https://get.acme.sh | sh;
 WORKDIR /var/www/
 CMD ["nginx"]
diff --git a/docker/nginx/sites-dev/default.conf b/docker/nginx/sites-dev/default.conf
new file mode 100644
index 0000000..3073bce
--- /dev/null
+++ b/docker/nginx/sites-dev/default.conf
@@ -0,0 +1,27 @@
+server {
+    listen 80 default_server;
+    listen [::]:80 default_server ipv6only=on;
+
+    server_name localhost;
+    root /var/www/symfony/public;
+    index index.php index.html index.htm;
+
+    location / {
+        try_files $uri $uri/ /index.php$is_args$args;
+    }
+
+    location ~ \.php$ {
+        try_files $uri /index.php =404;
+        fastcgi_pass php-upstream;
+        fastcgi_index index.php;
+        fastcgi_buffers 16 16k;
+        fastcgi_buffer_size 32k;
+        fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
+        fastcgi_read_timeout 600;
+        include fastcgi_params;
+    }
+
+    location ~ /\.ht {
+        deny all;
+    }
+}
diff --git a/docker/nginx/sites/default.conf b/docker/nginx/sites/default.conf
index 9b09e80..f6f05cd 100644
--- a/docker/nginx/sites/default.conf
+++ b/docker/nginx/sites/default.conf
@@ -1,13 +1,22 @@
 server {
+    listen 443 ssl;
     listen 80 default_server;
     listen [::]:80 default_server ipv6only=on;
 
-    server_name localhost;
+    server_name heatmap.zcu.cz www.heatmap.zcu.cz;
+    ssl_certificate /etc/letsencrypt/heatmap.zcu.cz/heatmap.zcu.cz.cer;
+    ssl_certificate_key /etc/letsencrypt/heatmap.zcu.cz/privkey.key;
+
+    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
+    ssl_prefer_server_ciphers on;
+    ssl_ciphers 'EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH';
+
     root /var/www/symfony/public;
+
     index index.php index.html index.htm;
 
     location / {
-         try_files $uri $uri/ /index.php$is_args$args;
+        try_files $uri $uri/ /index.php$is_args$args;
     }
 
     location ~ \.php$ {
diff --git a/docker/php-fpm/dev/Dockerfile b/docker/php-fpm/dev/Dockerfile
index 863f2d9..3d52589 100644
--- a/docker/php-fpm/dev/Dockerfile
+++ b/docker/php-fpm/dev/Dockerfile
@@ -1,27 +1,27 @@
 #DEV ONLY DOCKERFILE
 FROM php:7.4-fpm-alpine
 RUN apk update; \
-	apk upgrade; \
+    apk upgrade; \
     apk add --no-cache $PHPIZE_DEPS; \
     pecl install xdebug-2.9.5; \
     docker-php-ext-enable xdebug; \
-	apk add autoconf openssl-dev g++ make && \
-	pecl install mongodb && \
-	docker-php-ext-enable mongodb; \
-	apk del --purge autoconf openssl-dev g++ make;
+    apk add autoconf openssl-dev g++ make && \
+    pecl install mongodb && \
+    docker-php-ext-enable mongodb; \
+    apk del --purge autoconf openssl-dev g++ make;
 RUN apk add npm;
 RUN echo "**** install PHP Composer ****\n" && \
     curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/bin --filename=composer
 RUN rm -rf /usr/local/etc/php/conf.d/docker-php-ext-igbinary.ini;
 RUN rm -fr /usr/local/etc/php/conf.d/docker-php-ext-sodium.ini;
 RUN { \
-        echo '[xdebug]'; \
-        echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)"; \
-        echo 'xdebug.remote_enable = 1'; \
-        echo 'xdebug.remote_port = 9001'; \
-        echo 'xdebug.remote_autostart = 1'; \
-        echo 'xdebug.remote_connect_back = 0'; \
-        echo 'xdebug.remote_host = localhost'; \
-        echo 'xdebug.idekey = VSCODE'; \
-        echo 'xdebug.remote_log=/var/www/symfony/xdebug/xdebug.log'; \
+    echo '[xdebug]'; \
+    echo "zend_extension=$(find /usr/local/lib/php/extensions/ -name xdebug.so)"; \
+    echo 'xdebug.remote_enable = 1'; \
+    echo 'xdebug.remote_port = 9001'; \
+    echo 'xdebug.remote_autostart = 1'; \
+    echo 'xdebug.remote_connect_back = 0'; \
+    echo 'xdebug.remote_host = localhost'; \
+    echo 'xdebug.idekey = VSCODE'; \
+    echo 'xdebug.remote_log=/var/www/symfony/xdebug/xdebug.log'; \
     } > /usr/local/etc/php/conf.d/php-config.ini
diff --git a/scripts/dev/build.sh b/scripts/dev/build.sh
index 1689ed7..bd7ac00 100755
--- a/scripts/dev/build.sh
+++ b/scripts/dev/build.sh
@@ -3,24 +3,24 @@
 docker-compose -f docker-compose.yml -f docker-compose-dev.yml up --build -d
 
 cat << "EOF"
- ______  ______  __    __  ______ ______  ______  ______  ______       __  __   __  ______  ______ ______  __      __        
-/\  ___\/\  __ \/\ "-./  \/\  == /\  __ \/\  ___\/\  ___\/\  == \     /\ \/\ "-.\ \/\  ___\/\__  _/\  __ \/\ \    /\ \       
-\ \ \___\ \ \/\ \ \ \-./\ \ \  _-\ \ \/\ \ \___  \ \  __\\ \  __<     \ \ \ \ \-.  \ \___  \/_/\ \\ \  __ \ \ \___\ \ \____  
- \ \_____\ \_____\ \_\ \ \_\ \_\  \ \_____\/\_____\ \_____\ \_\ \_\    \ \_\ \_\\"\_\/\_____\ \ \_\\ \_\ \_\ \_____\ \_____\ 
-  \/_____/\/_____/\/_/  \/_/\/_/   \/_____/\/_____/\/_____/\/_/ /_/     \/_/\/_/ \/_/\/_____/  \/_/ \/_/\/_/\/_____/\/_____/                                                                                                                                                                                                                                                                                                                                                                                                                                      
+ ______  ______  __    __  ______ ______  ______  ______  ______       __  __   __  ______  ______ ______  __      __
+/\  ___\/\  __ \/\ "-./  \/\  == /\  __ \/\  ___\/\  ___\/\  == \     /\ \/\ "-.\ \/\  ___\/\__  _/\  __ \/\ \    /\ \
+\ \ \___\ \ \/\ \ \ \-./\ \ \  _-\ \ \/\ \ \___  \ \  __\\ \  __<     \ \ \ \ \-.  \ \___  \/_/\ \\ \  __ \ \ \___\ \ \____
+ \ \_____\ \_____\ \_\ \ \_\ \_\  \ \_____\/\_____\ \_____\ \_\ \_\    \ \_\ \_\\"\_\/\_____\ \ \_\\ \_\ \_\ \_____\ \_____\
+  \/_____/\/_____/\/_/  \/_/\/_/   \/_____/\/_____/\/_____/\/_/ /_/     \/_/\/_/ \/_/\/_____/  \/_/ \/_/\/_/\/_____/\/_____/
 EOF
 docker-compose exec php-fpm composer config extra.symfony.allow-contrib true --no-interaction --working-dir=/var/www/symfony
 docker-compose exec php-fpm composer update --no-interaction --working-dir=/var/www/symfony
 docker-compose exec php-fpm composer install --no-interaction --working-dir=/var/www/symfony
 
 cat << "EOF"
- ________    ________   _____ ______           ___   ________    ________   _________   ________   ___        ___          
-|\   ___  \ |\   __  \ |\   _ \  _   \        |\  \ |\   ___  \ |\   ____\ |\___   ___\|\   __  \ |\  \      |\  \         
-\ \  \\ \  \\ \  \|\  \\ \  \\\__\ \  \       \ \  \\ \  \\ \  \\ \  \___|_\|___ \  \_|\ \  \|\  \\ \  \     \ \  \        
- \ \  \\ \  \\ \   ____\\ \  \\|__| \  \       \ \  \\ \  \\ \  \\ \_____  \    \ \  \  \ \   __  \\ \  \     \ \  \       
-  \ \  \\ \  \\ \  \___| \ \  \    \ \  \       \ \  \\ \  \\ \  \\|____|\  \    \ \  \  \ \  \ \  \\ \  \____ \ \  \____  
+ ________    ________   _____ ______           ___   ________    ________   _________   ________   ___        ___
+|\   ___  \ |\   __  \ |\   _ \  _   \        |\  \ |\   ___  \ |\   ____\ |\___   ___\|\   __  \ |\  \      |\  \
+\ \  \\ \  \\ \  \|\  \\ \  \\\__\ \  \       \ \  \\ \  \\ \  \\ \  \___|_\|___ \  \_|\ \  \|\  \\ \  \     \ \  \
+ \ \  \\ \  \\ \   ____\\ \  \\|__| \  \       \ \  \\ \  \\ \  \\ \_____  \    \ \  \  \ \   __  \\ \  \     \ \  \
+  \ \  \\ \  \\ \  \___| \ \  \    \ \  \       \ \  \\ \  \\ \  \\|____|\  \    \ \  \  \ \  \ \  \\ \  \____ \ \  \____
    \ \__\\ \__\\ \__\     \ \__\    \ \__\       \ \__\\ \__\\ \__\ ____\_\  \    \ \__\  \ \__\ \__\\ \_______\\ \_______\
     \|__| \|__| \|__|      \|__|     \|__|        \|__| \|__| \|__||\_________\    \|__|   \|__|\|__| \|_______| \|_______|
                                                                    \|_________|
 EOF
-docker-compose exec php-fpm /bin/sh -c 'cd /var/www/symfony && npm install' 
\ No newline at end of file
+docker-compose exec php-fpm /bin/sh -c 'cd /var/www/symfony && npm install'
\ No newline at end of file
diff --git a/scripts/renew_certificate.sh b/scripts/renew_certificate.sh
new file mode 100755
index 0000000..85f5f4e
--- /dev/null
+++ b/scripts/renew_certificate.sh
@@ -0,0 +1,18 @@
+#!/bin/bash
+# Usage
+# if you want create new license run: renew_certificate new
+# if you want re-create the existing license run: renew_certificate
+
+if [ "$1" = "new" ]; then
+    docker-compose exec nginx /bin/sh -c "
+    cd /etc/letsencrypt && mkdir heatmap.zcu.cz && cd heatmap.zcu.cz; \
+    openssl dhparam -dsaparam -out dhparams.pem 4096; \
+    bash /root/.acme.sh/acme.sh --issue -w /var/www/symfony -d heatmap.zcu.cz -k 4096; \
+    bash /root/.acme.sh/acme.sh --installcert -d heatmap.zcu.cz \
+    --key-file /root/.acme.sh/heatmap.zcu.cz/heatmap.zcu.cz.key \
+    --fullchain-file /root/.acme.sh/heatmap.zcu.cz/fullchain.cer \
+    --reloadcmd 'bash /etc/init.d/nginx reload';
+    ";
+else
+    docker-compose exec nginx /bin/sh -c "acme.sh --renew -d heatmap.zcu.cz";
+fi
\ No newline at end of file
