Files
DLE/frontend/nginx-tunnel.conf

170 lines
6.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.

# Финальная безопасная конфигурация nginx
# Включаем WAF конфигурацию
# include /etc/nginx/conf.d/waf.conf;
# Блокировка всех подозрительных поддоменов
server {
listen 80;
server_name _;
# Возвращаем 444 (Connection Closed Without Response) для всех неизвестных доменов
return 444;
# Логируем попытки доступа к подозрительным доменам
access_log /var/log/nginx/suspicious_domains.log;
}
# Основной сервер только для легитимных доменов
server {
listen 80;
server_name hb3-accelerator.com www.hb3-accelerator.com localhost 127.0.0.1;
root /usr/share/nginx/html;
index index.html;
# Блокировка по WAF правилам
# if ($bad_ip = 1) {
# return 403;
# }
# if ($bad_bot = 1) {
# return 403;
# }
# if ($bad_request = 1) {
# return 404;
# }
# if ($bad_domain = 1) {
# return 404;
# }
# Блокировка агрессивных сканеров
if ($http_user_agent ~* (sqlmap|nikto|dirb|gobuster|wfuzz|burp|zap|nessus|openvas)) {
return 403;
}
# Блокировка только очень старых браузеров (до Chrome 50)
if ($http_user_agent ~* "Chrome/[1-4][0-9]\.") {
return 403;
}
# Блокировка только очень старых Safari (до версии 500)
if ($http_user_agent ~* "Safari/[1-4][0-9][0-9]\.") {
return 403;
}
# Дополнительная проверка подозрительных поддоменов
if ($host ~* "^(test|dev|staging|admin|beta|demo|old|new|backup|www2|www3|www4|www5|www6|www7|www8|www9|www10)\.hb3-accelerator\.com$") {
return 404;
}
# Блокировка сканирования резервных копий и архивов
if ($request_uri ~* "(backup|backups|bak|old|restore|www\.tar|website\.tar|\.tar\.gz|\.gz|\.sql\.tar|public_html\.tar|sftp-config\.json)") {
return 404;
}
# Блокировка опасных файлов (НЕ блокируем .js, .css)
if ($request_uri ~* "\.(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|bak|old|tmp|temp|swp|swo|~)$") {
return 404;
}
# Блокировка WordPress сканирования
if ($request_uri ~* "(wp-admin|wp-content|wp-includes|wp-config|wp-login|xmlrpc)") {
return 404;
}
# Блокировка path traversal
if ($request_uri ~* "(\.\.|\.\./|\.\.\\|\.\.%2f|\.\.%5c)") {
return 404;
}
# Блокировка конкретных атакующих IP
if ($remote_addr = "198.55.98.76") {
return 403;
}
# Блокировка всех запросов к конфигурационным файлам
if ($request_uri ~* "(config\.js|sftp-config\.json|\.config\.|\.conf\.|\.ini\.|\.env\.|\.json\.)") {
return 404;
}
# Основной location
location / {
try_files $uri $uri/ /index.html =404;
# Заголовки безопасности
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' ws: wss:;" always;
add_header Permissions-Policy "geolocation=(), microphone=(), camera=()" always;
}
# API с дополнительной защитой
location /api/ {
proxy_pass http://dapp-backend:8000/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;
# Таймауты
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 30s;
# Заголовки безопасности для 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 с защитой
location /ws {
proxy_pass http://dapp-backend:8000;
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;
# Таймауты для WebSocket
proxy_connect_timeout 30s;
proxy_send_timeout 30s;
proxy_read_timeout 300s;
}
# Статические файлы с кешированием и защитой
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;
}
# Запрет доступа к чувствительным файлам
location ~* /(\.htaccess|\.htpasswd|\.env|\.git|\.svn|\.DS_Store|Thumbs\.db|web\.config|robots\.txt|sitemap\.xml)$ {
deny all;
return 404;
}
# Строгая защита от доступа к конфигурационным файлам
location ~* /\.(env|config|ini|conf|cfg|yml|yaml|json|xml|sql|db|bak|backup|old|tmp|temp|log)$ {
deny all;
return 404;
}
# Скрытие информации о сервере
server_tokens off;
# Логирование ошибок
error_log /var/log/nginx/error.log warn;
access_log /var/log/nginx/access.log combined;
}