From b94658713e01e825321bda3199b23af84009e3f0 Mon Sep 17 00:00:00 2001 From: rasulov1337 <117843890+rasulov1337@users.noreply.github.com> Date: Mon, 16 Dec 2024 18:28:44 +0300 Subject: [PATCH] Deploy (#40) * feat: add caching * feat: fix docker-compose * fix command * fix shit * fix * image fix --- .gitignore | 3 +- docker-compose-debug.yml | 25 ++++++++ docker-compose.yml | 51 ++++++++-------- nginx/generate-certs.sh | 16 ++--- nginx/nginx-dev.conf | 62 +++++++++++++++++++ nginx/nginx.conf | 129 ++++++++++++++++++++------------------- 6 files changed, 191 insertions(+), 95 deletions(-) create mode 100644 docker-compose-debug.yml create mode 100644 nginx/nginx-dev.conf diff --git a/.gitignore b/.gitignore index 39227882..987611b8 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ node_modules/ .idea/ precompiled-templates.js /images/ -/nginx/ssl/ \ No newline at end of file +/nginx/ssl/ +dist/ \ No newline at end of file diff --git a/docker-compose-debug.yml b/docker-compose-debug.yml new file mode 100644 index 00000000..ba41541a --- /dev/null +++ b/docker-compose-debug.yml @@ -0,0 +1,25 @@ +services: + frontend: + image: node:20 + working_dir: /app + volumes: + - ./:/app + - /app/node_modules + ports: + - '5173:5173' # For local development! + command: > + sh -c "npm i && npm run start" + + nginx: + image: nginx:latest + volumes: + - ./nginx/:/etc/nginx/ + ports: + - '80:80' + - '443:443' + depends_on: + - frontend + extra_hosts: + - 'host.docker.internal:host-gateway' + command: > + sh -c "chmod +x /etc/nginx/generate-certs.sh && sh /etc/nginx/generate-certs.sh" diff --git a/docker-compose.yml b/docker-compose.yml index ba41541a..835b10c3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,25 +1,26 @@ -services: - frontend: - image: node:20 - working_dir: /app - volumes: - - ./:/app - - /app/node_modules - ports: - - '5173:5173' # For local development! - command: > - sh -c "npm i && npm run start" - - nginx: - image: nginx:latest - volumes: - - ./nginx/:/etc/nginx/ - ports: - - '80:80' - - '443:443' - depends_on: - - frontend - extra_hosts: - - 'host.docker.internal:host-gateway' - command: > - sh -c "chmod +x /etc/nginx/generate-certs.sh && sh /etc/nginx/generate-certs.sh" +version: '3.8' + +services: + frontend: + image: node:20 + working_dir: /app + volumes: + - .:/app + - /app/node_modules + command: > + sh -c "npm i && npm run start" + + nginx: + image: nginx:latest + volumes: + - ./nginx/:/etc/nginx/ + # - ./app:/app/ # изменено на правильный путь + ports: + - '80:80' + - '443:443' + depends_on: + - frontend + extra_hosts: + - 'host.docker.internal:host-gateway' + command: > + sh /etc/nginx/generate-certs.sh diff --git a/nginx/generate-certs.sh b/nginx/generate-certs.sh index 91429ca8..928e60ff 100755 --- a/nginx/generate-certs.sh +++ b/nginx/generate-certs.sh @@ -1,12 +1,14 @@ #!/bin/bash -# Установка OpenSSL, если он не установлен -if ! command -v openssl &> /dev/null; then - echo "OpenSSL не найден. Устанавливаем..." - apt update && apt install -y openssl -else - echo "OpenSSL уже установлен." -fi +# # Установка OpenSSL, если он не установлен +# if ! command -v openssl &> /dev/null; then +# echo "OpenSSL не найден. Устанавливаем..." +# apt update && apt install -y openssl +# else +# echo "OpenSSL уже установлен." +# fi + +ls /app/ -la # Папка для хранения сертификатов CERT_DIR="/etc/nginx/ssl" diff --git a/nginx/nginx-dev.conf b/nginx/nginx-dev.conf new file mode 100644 index 00000000..da5ad779 --- /dev/null +++ b/nginx/nginx-dev.conf @@ -0,0 +1,62 @@ +events { } + +http { + server { + listen 80; + server_name localhost; + + # Перенаправление всех HTTP-запросов на HTTPS + return 301 http://$host$request_uri; + } + + server { + listen 443 ssl http2; + server_name localhost; + + ssl_certificate /etc/nginx/ssl/pootnick.crt; + ssl_certificate_key /etc/nginx/ssl/pootnick.key; + ssl_protocols TLSv1.2 TLSv1.3; + + location /api/ { + proxy_pass http://host.docker.internal:8008/api/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /websocket/ { + proxy_pass https://host.docker.internal:8008/api/messages/setconn; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_buffering off; + proxy_read_timeout 86400; + } + + location /images/default.png { + proxy_pass http://frontend:5173/default.png; + } + + location /images/ { + proxy_pass http://host.docker.internal:9000; # Minio + proxy_set_header Host $host; + } + + location /cities/ { + proxy_pass http://host.docker.internal:9000; # Minio + proxy_set_header Host $host; + } + + location / { + proxy_pass http://frontend:5173; # Vite + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + } +} diff --git a/nginx/nginx.conf b/nginx/nginx.conf index da5ad779..ac0418b6 100644 --- a/nginx/nginx.conf +++ b/nginx/nginx.conf @@ -1,62 +1,67 @@ -events { } - -http { - server { - listen 80; - server_name localhost; - - # Перенаправление всех HTTP-запросов на HTTPS - return 301 http://$host$request_uri; - } - - server { - listen 443 ssl http2; - server_name localhost; - - ssl_certificate /etc/nginx/ssl/pootnick.crt; - ssl_certificate_key /etc/nginx/ssl/pootnick.key; - ssl_protocols TLSv1.2 TLSv1.3; - - location /api/ { - proxy_pass http://host.docker.internal:8008/api/; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header X-Forwarded-Proto $scheme; - } - - location /websocket/ { - proxy_pass https://host.docker.internal:8008/api/messages/setconn; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; - proxy_set_header Host $host; - proxy_set_header X-Real-IP $remote_addr; - proxy_buffering off; - proxy_read_timeout 86400; - } - - location /images/default.png { - proxy_pass http://frontend:5173/default.png; - } - - location /images/ { - proxy_pass http://host.docker.internal:9000; # Minio - proxy_set_header Host $host; - } - - location /cities/ { - proxy_pass http://host.docker.internal:9000; # Minio - proxy_set_header Host $host; - } - - location / { - proxy_pass http://frontend:5173; # Vite - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection 'upgrade'; - proxy_set_header Host $host; - proxy_cache_bypass $http_upgrade; - } - } -} +events { } + +http { + server { + listen 80; + server_name localhost; + + # Перенаправление всех HTTP-запросов на HTTPS + return 301 http://$host$request_uri; + } + + server { + listen 443 ssl http2; + server_name localhost; + + ssl_certificate /etc/nginx/ssl/pootnick.crt; + ssl_certificate_key /etc/nginx/ssl/pootnick.key; + ssl_protocols TLSv1.2 TLSv1.3; + + location /api/ { + proxy_pass http://host.docker.internal:8008/api/; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header X-Forwarded-Proto $scheme; + } + + location /websocket/ { + proxy_pass https://host.docker.internal:8008/api/messages/setconn; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; + proxy_buffering off; + proxy_read_timeout 86400; + } + + location /images/ { + proxy_pass http://host.docker.internal:9000; # Minio + expires 30d; + add_header Cache-Control "public"; # public = browsers + CDN + proxy_set_header Host $host; + } + + location /cities/ { + proxy_pass http://host.docker.internal:9000; # Minio + proxy_set_header Host $host; + } + + # location ~* \.(css|jpg|png|jpeg)$ { + # root /app/dist/; + # expires 30d; + # proxy_pass http://frontend:5173; # Vite + # add_header Cache-Control "public"; # public = browsers + CDN + # } + + location / { + proxy_pass http://frontend:5173; # Vite + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection 'upgrade'; + proxy_set_header Host $host; + proxy_cache_bypass $http_upgrade; + } + } +}