105 lines
3.9 KiB
Nginx Configuration File
105 lines
3.9 KiB
Nginx Configuration File
# ==============================================
|
|
# Nginx главная конфигурация
|
|
# ==============================================
|
|
|
|
user nginx;
|
|
worker_processes auto;
|
|
error_log /var/log/nginx/error.log warn;
|
|
pid /var/run/nginx.pid;
|
|
|
|
events {
|
|
worker_connections 1024;
|
|
use epoll;
|
|
multi_accept on;
|
|
}
|
|
|
|
http {
|
|
include /etc/nginx/mime.types;
|
|
default_type application/octet-stream;
|
|
|
|
# ==============================================
|
|
# ЛОГИРОВАНИЕ
|
|
# ==============================================
|
|
log_format main '$remote_addr - $remote_user [$time_local] "$request" '
|
|
'$status $body_bytes_sent "$http_referer" '
|
|
'"$http_user_agent" "$http_x_forwarded_for"';
|
|
|
|
access_log /var/log/nginx/access.log main;
|
|
|
|
# ==============================================
|
|
# ПРОИЗВОДИТЕЛЬНОСТЬ
|
|
# ==============================================
|
|
sendfile on;
|
|
tcp_nopush on;
|
|
tcp_nodelay on;
|
|
keepalive_timeout 65;
|
|
types_hash_max_size 2048;
|
|
client_max_body_size 100M;
|
|
|
|
# ==============================================
|
|
# GZIP СЖАТИЕ
|
|
# ==============================================
|
|
gzip on;
|
|
gzip_vary on;
|
|
gzip_proxied any;
|
|
gzip_comp_level 6;
|
|
gzip_types text/plain text/css text/xml text/javascript
|
|
application/json application/javascript application/xml+rss
|
|
application/rss+xml font/truetype font/opentype
|
|
application/vnd.ms-fontobject image/svg+xml;
|
|
gzip_disable "msie6";
|
|
|
|
# ==============================================
|
|
# БЕЗОПАСНОСТЬ
|
|
# ==============================================
|
|
server_tokens off;
|
|
# Отключаем X-Frame-Options для работы Telegram Login Widget (управляем через CSP)
|
|
# add_header X-Frame-Options "SAMEORIGIN" always;
|
|
add_header X-Content-Type-Options "nosniff" always;
|
|
add_header X-XSS-Protection "1; mode=block" always;
|
|
# CSP для Telegram Login Widget - разрешаем локальный API и Telegram iframe
|
|
add_header Content-Security-Policy "default-src 'self' http: https: data: blob: 'unsafe-inline'; frame-src 'self' https://oauth.telegram.org https://*.telegram.org http://localhost:* http://127.0.0.1:*; script-src 'self' 'unsafe-inline' 'unsafe-eval' https://telegram.org https://*.telegram.org; connect-src 'self' http://localhost:* http://127.0.0.1:* ws://localhost:* ws://127.0.0.1:* wss://localhost:* wss://127.0.0.1:* https://api.telegram.org https://*.telegram.org" always;
|
|
|
|
# ==============================================
|
|
# RATE LIMITING
|
|
# ==============================================
|
|
limit_req_zone $binary_remote_addr zone=api_limit:10m rate=10r/s;
|
|
limit_req_zone $binary_remote_addr zone=general_limit:10m rate=30r/s;
|
|
limit_req_zone $binary_remote_addr zone=login_limit:10m rate=5r/m;
|
|
limit_conn_zone $binary_remote_addr zone=conn_limit:10m;
|
|
limit_req_status 429;
|
|
|
|
# ==============================================
|
|
# UPSTREAM СЕРВЕРЫ
|
|
# ==============================================
|
|
upstream django {
|
|
least_conn;
|
|
server web:8000 max_fails=3 fail_timeout=30s;
|
|
keepalive 32;
|
|
}
|
|
|
|
# Алиас для backend (используется в platform.conf)
|
|
upstream backend {
|
|
least_conn;
|
|
server web:8000 max_fails=3 fail_timeout=30s;
|
|
keepalive 32;
|
|
}
|
|
|
|
upstream frontend {
|
|
least_conn;
|
|
server front_material:3000 max_fails=3 fail_timeout=30s;
|
|
keepalive 32;
|
|
}
|
|
|
|
upstream livekit {
|
|
server livekit:7880 max_fails=3 fail_timeout=30s;
|
|
keepalive 4;
|
|
}
|
|
|
|
# ==============================================
|
|
# ВКЛЮЧЕНИЕ КОНФИГУРАЦИЙ САЙТОВ
|
|
# ==============================================
|
|
include /etc/nginx/conf.d/*.conf;
|
|
}
|
|
|