Files
api-copp/nginx.production.conf
2026-04-07 15:37:04 +05:00

121 lines
5.5 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# ============================================================
# nginx — production config для test.cloud-copp74.ru
# Устанавливается на отдельном nginx-сервере с certbot.
#
# Замените APP_IP на внутренний IP сервера с Docker.
#
# Первый запуск (получение сертификата):
# 1. Разместите этот файл в /etc/nginx/sites-available/copp
# 2. Создайте симлинк: ln -s /etc/nginx/sites-available/copp /etc/nginx/sites-enabled/
# 3. Временно раскомментируйте блок certbot-challenge (см. ниже)
# 4. nginx -t && systemctl reload nginx
# 5. certbot --nginx -d test.cloud-copp74.ru
# 6. certbot создаст ssl-блок автоматически или используйте конфиг ниже
# ============================================================
# Сервер приложения
upstream flet_app {
server 192.168.1.18:80;
keepalive 32;
}
# ── HTTP → HTTPS редирект ────────────────────────────────────
server {
listen 80;
listen [::]:80;
server_name test.cloud-copp74.ru;
# certbot challenge (оставьте всегда, certbot сам обновляет сертификат)
location /.well-known/acme-challenge/ {
root /var/www/certbot;
}
location / {
return 301 https://$host$request_uri;
}
}
# ── HTTPS ────────────────────────────────────────────────────
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
server_name test.cloud-copp74.ru;
# Сертификаты Let's Encrypt (certbot заполнит сам, или укажите вручную)
ssl_certificate /etc/letsencrypt/live/test.cloud-copp74.ru/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/test.cloud-copp74.ru/privkey.pem;
include /etc/letsencrypt/options-ssl-nginx.conf;
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
# ── Безопасность ────────────────────────────────────────
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options SAMEORIGIN always;
add_header X-Content-Type-Options nosniff always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
# ── Производительность ──────────────────────────────────
gzip on;
gzip_types text/plain text/css application/javascript application/json image/svg+xml;
gzip_min_length 1024;
gzip_comp_level 5;
gzip_vary on;
client_max_body_size 16m;
# ── WebSocket (Flet) ────────────────────────────────────
# Flet держит постоянное WS-соединение на /ws
location /ws {
proxy_pass http://flet_app;
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_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
# Долгоживущие WS-соединения — не рвать
proxy_read_timeout 3600s;
proxy_send_timeout 3600s;
proxy_connect_timeout 10s;
}
# ── Статика Flet (assets, иконки) ───────────────────────
location ~* \.(js|css|woff2?|svg|png|jpg|ico|webp)$ {
proxy_pass http://flet_app;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-Proto $scheme;
# Кешируем статику на клиенте 7 дней
expires 7d;
add_header Cache-Control "public, immutable";
access_log off;
}
# ── SVG диаграмма (radar-image) ─────────────────────────
location /radar-image/ {
proxy_pass http://flet_app;
proxy_http_version 1.1;
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;
proxy_read_timeout 30s;
}
# ── Всё остальное → Flet app ────────────────────────────
location / {
proxy_pass http://flet_app;
proxy_http_version 1.1;
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;
proxy_set_header Connection "";
proxy_connect_timeout 10s;
proxy_read_timeout 60s;
proxy_send_timeout 60s;
}
}