Files
DLE/frontend/nginx-simple.conf

231 lines
9.3 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.

events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# Убираем ограничение по размеру загружаемых файлов (база данных масштабируется)
client_max_body_size 0;
# Rate limiting для защиты от DDoS (отключено - лимиты убраны)
# limit_req_zone $binary_remote_addr zone=req_limit_per_ip:10m rate=10r/s;
# limit_req_zone $binary_remote_addr zone=api_limit_per_ip:10m rate=5r/s;
# Блокировка известных сканеров и вредоносных ботов (исключая легитимные поисковые боты)
# ВАЖНО: Сначала проверяем легитимные боты, потом блокируем вредоносные
map $http_user_agent $bad_bot {
default 0;
# Разрешаем легитимные поисковые боты (проверяем ПЕРВЫМИ)
~*googlebot 0;
~*google.*bot 0;
~*bingbot 0;
~*bingpreview 0;
~*slurp 0;
~*duckduckbot 0;
~*baiduspider 0;
~*yandex 0;
~*yandexbot 0;
~*sogou 0;
~*exabot 0;
~*facebot 0;
~*facebookexternalhit 0;
~*ia_archiver 0;
~*archive\.org_bot 0;
~*applebot 0;
~*twitterbot 0;
~*linkedinbot 0;
~*slackbot 0;
~*whatsapp 0;
~*telegrambot 0;
# Блокируем вредоносные боты и сканеры (только если не поисковый бот)
~*sqlmap 1;
~*nikto 1;
~*dirb 1;
~*gobuster 1;
~*wfuzz 1;
~*burp 1;
~*zap 1;
~*nessus 1;
~*openvas 1;
~*masscan 1;
~*nmap 1;
~*scanner 1;
# Блокируем старые версии браузеров (только если это не поисковый бот)
# Убираем блокировку старых браузеров - может блокировать легитимных ботов
# ~*Chrome/[1-4][0-9]\. 1;
# ~*Firefox/[1-6][0-9]\. 1;
# ~*Safari/[1-9]\. 1;
# ~*MSIE\ [1-9]\. 1;
}
# HTTP сервер - редирект на HTTPS
server {
listen 80;
server_name ${DOMAIN};
# Редирект всех HTTP запросов на HTTPS
return 301 https://$server_name$request_uri;
}
# HTTPS сервер
server {
listen 443 ssl http2;
server_name ${DOMAIN};
# SSL конфигурация (автоматически обновляется certbot)
ssl_certificate /etc/letsencrypt/live/${DOMAIN}/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/${DOMAIN}/privkey.pem;
# Современные SSL настройки
ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-RSA-AES256-GCM-SHA512:DHE-RSA-AES256-GCM-SHA512:ECDHE-RSA-AES256-GCM-SHA384:DHE-RSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-SHA384;
ssl_prefer_server_ciphers off;
ssl_session_cache shared:SSL:10m;
ssl_session_timeout 10m;
# HSTS
add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
root /usr/share/nginx/html;
index index.html;
# Блокировка подозрительных ботов
if ($bad_bot = 1) {
return 403;
}
# Защита от path traversal
if ($request_uri ~* "(\.\.|\.\./|\.\.\\|\.\.%2f|\.\.%5c)") {
return 404;
}
# Защита от опасных расширений
location ~* \.(zip|rar|7z|tar|gz|bz2|xz|sql|sqlite|db|bak|backup|old|csv|php|asp|aspx|jsp|cgi|pl|py|sh|bash|exe|bat|cmd|com|pif|scr|vbs|vbe|jar|war|ear|dll|so|dylib|bin|sys|ini|log|tmp|temp|swp|swo|~)$ {
return 404;
}
# Защита от доступа к чувствительным файлам (исключаем robots.txt и sitemap.xml для SEO)
location ~* /(\.htaccess|\.htpasswd|\.env|\.git|\.svn|\.DS_Store|Thumbs\.db|web\.config)$ {
deny all;
return 404;
}
# Разрешаем доступ к robots.txt и sitemap.xml для поисковых систем
location = /robots.txt {
proxy_pass http://${BACKEND_CONTAINER}:8000/api/pages/public/robots.txt;
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;
add_header Content-Type text/plain;
}
location = /sitemap.xml {
proxy_pass http://${BACKEND_CONTAINER}:8000/api/pages/public/sitemap.xml;
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;
add_header Content-Type application/xml;
}
# Защита от доступа к конфигурационным файлам
location ~* /\.(env|config|ini|conf|cfg|yml|yaml|json|xml|sql|db|bak|backup|old|tmp|temp|log)$ {
deny all;
return 404;
}
# Healthcheck endpoint
location /health {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
# Certbot webroot для автоматического получения SSL сертификатов
location /.well-known/acme-challenge/ {
root /var/www/certbot;
try_files $uri $uri/ =404;
}
# Основной location
location / {
# Rate limiting для основных страниц (отключено)
# limit_req zone=req_limit_per_ip burst=20 nodelay;
try_files $uri $uri/ /index.html;
# Базовые заголовки безопасности для HTTPS
add_header X-Frame-Options "DENY" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
add_header Referrer-Policy "strict-origin-when-cross-origin" always;
add_header Content-Security-Policy "default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline'; img-src 'self' data: https:; font-src 'self' data:; connect-src 'self' wss:;" always;
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
}
# Pre-rendered blog pages (SEO optimization)
location /blog {
root /usr/share/nginx/html;
try_files $uri $uri.html /blog/index.html /index.html;
# Заголовки для SEO
add_header Cache-Control "public, max-age=3600";
add_header X-Content-Type-Options "nosniff" always;
add_header X-Frame-Options "SAMEORIGIN" always;
}
# Статические файлы
location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
expires 1y;
add_header Cache-Control "public, immutable";
add_header Vary Accept-Encoding;
# Заголовки безопасности для статических файлов
add_header X-Content-Type-Options "nosniff" always;
}
# API
location /api/ {
# Rate limiting для API (отключено)
# limit_req zone=api_limit_per_ip burst=10 nodelay;
proxy_pass http://${BACKEND_CONTAINER}:8000/api/;
proxy_connect_timeout 120s;
proxy_send_timeout 120s;
proxy_read_timeout 600s;
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;
# Заголовки безопасности для API
add_header X-Frame-Options "DENY" always;
add_header X-Content-Type-Options "nosniff" always;
add_header X-XSS-Protection "1; mode=block" always;
}
# WebSocket поддержка (HTTPS)
location /ws {
proxy_pass http://${BACKEND_CONTAINER}:8000/ws;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_connect_timeout 120s;
proxy_send_timeout 120s;
proxy_read_timeout 600s;
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 https;
proxy_set_header X-Forwarded-Host $host;
proxy_set_header X-Forwarded-Port $server_port;
}
# Скрытие информации о сервере
server_tokens off;
}
}