2026-03-20 21:07:25 +02:00
|
|
|
|
# nginx/baton.conf — шаблон конфигурации для деплоя Baton
|
|
|
|
|
|
#
|
|
|
|
|
|
# Замените <YOUR_DOMAIN> на реальный домен перед использованием.
|
|
|
|
|
|
# Токен бота НЕ включается в этот файл — он передаётся только через
|
|
|
|
|
|
# переменную окружения BOT_TOKEN в самом приложении.
|
|
|
|
|
|
#
|
|
|
|
|
|
# Деплой:
|
|
|
|
|
|
# sudo cp nginx/baton.conf /etc/nginx/sites-available/baton
|
|
|
|
|
|
# sudo ln -s /etc/nginx/sites-available/baton /etc/nginx/sites-enabled/baton
|
|
|
|
|
|
# sudo nginx -t && sudo systemctl reload nginx
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
# Маскировка BOT_TOKEN в access_log (defence in depth)
|
|
|
|
|
|
#
|
|
|
|
|
|
# Хотя текущий webhook-эндпоинт (/api/webhook/telegram) не содержит токен
|
|
|
|
|
|
# в URL, этот map-блок защищает на случай, если в будущем появится маршрут
|
|
|
|
|
|
# вида /bot<TOKEN>/... (например, при смене архитектуры или временном дебаге).
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
map $request_uri $masked_uri {
|
|
|
|
|
|
default $request_uri;
|
|
|
|
|
|
"~^(/bot)[^/]+(/.*)$" "$1[REDACTED]$2";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
log_format baton_secure '$remote_addr - $remote_user [$time_local] '
|
|
|
|
|
|
'"$request_method $masked_uri $server_protocol" '
|
|
|
|
|
|
'$status $body_bytes_sent '
|
|
|
|
|
|
'"$http_referer" "$http_user_agent"';
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
# HTTP → HTTPS redirect
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
server {
|
|
|
|
|
|
listen 80;
|
2026-03-20 22:32:05 +02:00
|
|
|
|
server_name baton.itafrika.com;
|
2026-03-20 21:07:25 +02:00
|
|
|
|
|
|
|
|
|
|
return 301 https://$server_name$request_uri;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
# HTTPS: проксирование к FastAPI (uvicorn на порту 8000)
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
server {
|
|
|
|
|
|
listen 443 ssl;
|
2026-03-20 22:32:05 +02:00
|
|
|
|
server_name baton.itafrika.com;
|
2026-03-20 21:07:25 +02:00
|
|
|
|
|
2026-03-20 22:32:05 +02:00
|
|
|
|
ssl_certificate /etc/letsencrypt/live/baton.itafrika.com/fullchain.pem;
|
|
|
|
|
|
ssl_certificate_key /etc/letsencrypt/live/baton.itafrika.com/privkey.pem;
|
2026-03-20 21:07:25 +02:00
|
|
|
|
|
|
|
|
|
|
ssl_protocols TLSv1.2 TLSv1.3;
|
|
|
|
|
|
ssl_prefer_server_ciphers on;
|
|
|
|
|
|
|
|
|
|
|
|
# Все запросы логируются с маскированным URI
|
|
|
|
|
|
access_log /var/log/nginx/baton_access.log baton_secure;
|
|
|
|
|
|
error_log /var/log/nginx/baton_error.log warn;
|
|
|
|
|
|
|
|
|
|
|
|
# Заголовки X-Telegram-Bot-Api-Secret-Token НЕ логируются —
|
|
|
|
|
|
# они передаются только в proxy_pass и не попадают в access_log.
|
2026-03-20 23:27:06 +02:00
|
|
|
|
|
|
|
|
|
|
# API → FastAPI
|
|
|
|
|
|
location /api/ {
|
2026-03-20 21:07:25 +02:00
|
|
|
|
proxy_pass http://127.0.0.1:8000;
|
|
|
|
|
|
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;
|
|
|
|
|
|
proxy_send_timeout 30s;
|
|
|
|
|
|
proxy_connect_timeout 5s;
|
|
|
|
|
|
}
|
2026-03-20 23:27:06 +02:00
|
|
|
|
|
|
|
|
|
|
# Health → FastAPI
|
|
|
|
|
|
location /health {
|
|
|
|
|
|
proxy_pass http://127.0.0.1:8000;
|
|
|
|
|
|
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;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-20 23:44:58 +02:00
|
|
|
|
# Admin API → FastAPI (UI-страница /admin.html раздаётся статикой ниже)
|
|
|
|
|
|
location /admin/users {
|
|
|
|
|
|
proxy_pass http://127.0.0.1:8000;
|
|
|
|
|
|
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;
|
|
|
|
|
|
proxy_send_timeout 30s;
|
|
|
|
|
|
proxy_connect_timeout 5s;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-03-21 07:58:56 +02:00
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
# Security headers
|
|
|
|
|
|
# IMPORTANT: must be repeated in every location block that uses add_header,
|
|
|
|
|
|
# because nginx does not inherit parent add_header when child block defines its own.
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
|
add_header X-Content-Type-Options nosniff always;
|
|
|
|
|
|
add_header X-Frame-Options DENY always;
|
|
|
|
|
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'" always;
|
|
|
|
|
|
|
2026-03-20 23:27:06 +02:00
|
|
|
|
# Статика фронтенда (SPA)
|
|
|
|
|
|
location / {
|
|
|
|
|
|
root /opt/baton/frontend;
|
|
|
|
|
|
try_files $uri /index.html;
|
2026-03-21 07:58:56 +02:00
|
|
|
|
expires 1h;
|
|
|
|
|
|
# Security headers repeated here because add_header in location blocks
|
|
|
|
|
|
# overrides parent-level add_header directives (nginx inheritance rule)
|
|
|
|
|
|
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
|
|
|
|
|
add_header X-Content-Type-Options nosniff always;
|
|
|
|
|
|
add_header X-Frame-Options DENY always;
|
|
|
|
|
|
add_header Content-Security-Policy "default-src 'self'; script-src 'self'; style-src 'self' 'unsafe-inline'; img-src 'self' data:; connect-src 'self'" always;
|
|
|
|
|
|
add_header Cache-Control "public" always;
|
2026-03-20 23:27:06 +02:00
|
|
|
|
}
|
2026-03-20 21:07:25 +02:00
|
|
|
|
}
|