Skip to content

Runbook: Nginx Security

Deny rules

Soubor: /etc/nginx/snippets/security-deny.conf (na hub-alfa i prod-alfa)

Blokované patterny

# PHP exploity
location ~ \.php$ { return 403; }

# Citlivé soubory
location ~ /\.env { return 403; }
location ~ /\.git { return 403; }
location ~ /\.aws { return 403; }

# WordPress / CMS útoky
location ~ /wp-admin { return 403; }
location ~ /wp-login { return 403; }
location ~ /phpmyadmin { return 403; }
location ~ /adminer { return 403; }

Použití v nginx config

server {
    ...
    include snippets/security-deny.conf;
    ...
}

SSL certifikáty

  • Certbot (Let's Encrypt) na hub-alfa i prod-alfa
  • Auto-renew přes cron/systemd timer
# Stav certifikátů
ssh root@<server_ip> "certbot certificates"

# Ruční obnova
ssh root@<server_ip> "certbot renew --dry-run"

# Nový certifikát pro novou doménu
ssh root@<server_ip> "certbot --nginx -d <domena>"

Audit

# Aktuální deny rules
ssh root@<server_ip> "cat /etc/nginx/snippets/security-deny.conf"

# Nginx config test
ssh root@<server_ip> "nginx -t"

# 403 požadavky za posledních 24h
ssh root@<server_ip> "grep ' 403 ' /var/log/nginx/access.log | wc -l"

# Top blokované cesty
ssh root@<server_ip> "grep ' 403 ' /var/log/nginx/access.log | awk '{print \$7}' | sort | uniq -c | sort -rn | head -20"

Přidání deny rule

  1. Přidat pravidlo do /etc/nginx/snippets/security-deny.conf na serveru
  2. nginx -t — ověřit syntax
  3. systemctl reload nginx
  4. Aktualizovat tento runbook

Porty

Všechny Docker služby bindované na 127.0.0.1 — žádný direct access. Nginx je jediný reverse proxy:

Internet → Nginx (80/443) → 127.0.0.1:<port> → Docker kontejner

Pokud Docker compose má ports: "0.0.0.0:<port>:<port>" — OPRAVIT na 127.0.0.1:<port>:<port>.