ModSecurity
Запуск Docker
Оказалось несколько сложнее. ИИ не дает полного ответа, нужно отстраивать по частям. Есть разные образы nginx-modsecurity.
Структура проекта:
nginx-modsecurity/
├── docker-compose.yml
├── nginx.conf
├── modsecurity.conf
└── html/
└── index.html
docker-compose.yml
version: '3.8'
services:
nginx-modsecurity:
image: coreruleset/modsecurity-crs:nginx
container_name: nginx-modsecurity
ports:
- "80:80"
- "443:443"
volumes:
- ./nginx/nginx.conf:/etc/nginx/nginx.conf
- ./nginx/modsecurity.conf:/etc/modsecurity.d/modsecurity.conf
- ./html:/usr/share/nginx/html
environment:
- PARANOIA=1
- PROXY=0
restart: unless-stopped
nginx.conf
events {
worker_connections 1024;
}
http {
include /etc/nginx/mime.types;
default_type application/octet-stream;
# ModSecurity
modsecurity on;
modsecurity_rules_file /etc/modsecurity.d/modsecurity.conf;
server {
listen 80;
server_name localhost;
# Включение OWASP CRS правил
modsecurity_rules_file /etc/modsecurity.d/crs-setup.conf;
modsecurity_rules_file /etc/modsecurity.d/rules/*.conf;
location / {
root /usr/share/nginx/html;
index index.html;
modsecurity on;
}
# Health check endpoint
location /status {
access_log off;
return 200 "healthy\n";
add_header Content-Type text/plain;
}
}
}
index.html
<html>
<body>
Hello world
</body>
</html>
Запуск и тестирование
# Создайте необходимые файлы и директории
mkdir -p html modsec-audit
# Запустите контейнер
docker compose up -d
# Проверьте логи
docker compose logs -f
# Тестовые запросы
curl http://localhost/
curl "http://localhost/?test=<script>alert('xss')</script>"
modsecurity.conf в разделе Настройка modescurity
Проверка работы
# Просмотр логов блокировок
docker exec nginx-modsecurity tail -f /var/log/modsec_audit.log
# Проверка конфигурации
docker exec nginx-modsecurity nginx -t
# Просмотр загруженных правил
docker exec nginx-modsecurity ls -la /etc/modsecurity.d/rules/