Anwendungen sollten sich nicht direkt um SSL, WAF, Rate Limiting kümmern.
Architektur-Komponenten
- HAProxy + keepalived
- Nginx
- Varnish
- Traefik
- ModSecurity
- Let's Encrypt
Beispiel: Nginx-Reverse-Proxy
Ein minimaler, einsatzbereiter Block fuer eine App hinter Nginx mit TLS:
# /etc/nginx/conf.d/app.conf — reverse proxy + TLS
server {
listen 443 ssl;
server_name app.example.com;
ssl_certificate /etc/letsencrypt/live/app.example.com/fullchain.pem;
ssl_certificate_key /etc/letsencrypt/live/app.example.com/privkey.pem;
location / {
proxy_pass http://127.0.0.1:8080;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-Proto $scheme;
}
}
HAProxy: Backend mit Health-Checks
Ein HAProxy-Backend mit aktiver Server-Zustandspruefung:
frontend web
bind *:443 ssl crt /etc/haproxy/certs/site.pem
default_backend app
backend app
balance leastconn
option httpchk GET /health
http-check expect status 200
server app1 10.0.0.11:8080 check inter 2s fall 3 rise 2
server app2 10.0.0.12:8080 check inter 2s fall 3 rise 2
Nginx: Rate-Limiting gegen Missbrauch
Sie begrenzen Anfragen pro IP, um Scraping und L7-Angriffe zu stoppen:
# in http {}
limit_req_zone $binary_remote_addr zone=api:10m rate=10r/s;
# in location
location /api/ {
limit_req zone=api burst=20 nodelay;
limit_req_status 429;
proxy_pass http://app;
}
Nginx: Cache fuer oeffentliche Inhalte
Sie cachen Antworten, um die App-Last zu senken:
# in http {}
proxy_cache_path /var/cache/nginx levels=1:2 keys_zone=app:50m max_size=2g inactive=60m;
# in location
location / {
proxy_cache app;
proxy_cache_valid 200 10m;
proxy_cache_use_stale error timeout updating;
add_header X-Cache $upstream_cache_status;
proxy_pass http://backend;
}
WAF: ModSecurity + OWASP CRS
Sie blockieren Injektionen und L7-Angriffe mit einer WAF:
apt -y install libnginx-mod-http-modsecurity
# activezi + OWASP Core Rule Set
git clone https://github.com/coreruleset/coreruleset /etc/nginx/owasp-crs
# nginx.conf: modsecurity on; modsecurity_rules_file /etc/nginx/modsec/main.conf;
# incepi in DetectionOnly, apoi treci pe blocking dupa tuning
nginx -t && systemctl reload nginx