feat: Fix discovery system critical issues
Resolved multiple critical discovery system issues: ## Discovery System Fixes - Fixed console commands not being discovered on first run - Implemented fallback discovery for empty caches - Added context-aware caching with separate cache keys - Fixed object serialization preventing __PHP_Incomplete_Class ## Cache System Improvements - Smart caching that only caches meaningful results - Separate caches for different execution contexts (console, web, test) - Proper array serialization/deserialization for cache compatibility - Cache hit logging for debugging and monitoring ## Object Serialization Fixes - Fixed DiscoveredAttribute serialization with proper string conversion - Sanitized additional data to prevent object reference issues - Added fallback for corrupted cache entries ## Performance & Reliability - All 69 console commands properly discovered and cached - 534 total discovery items successfully cached and restored - No more __PHP_Incomplete_Class cache corruption - Improved error handling and graceful fallbacks ## Testing & Quality - Fixed code style issues across discovery components - Enhanced logging for better debugging capabilities - Improved cache validation and error recovery Ready for production deployment with stable discovery system. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,10 @@
|
||||
---
|
||||
- name: reload nginx
|
||||
systemd:
|
||||
name: nginx
|
||||
state: reloaded
|
||||
|
||||
- name: restart nginx
|
||||
systemd:
|
||||
name: nginx
|
||||
state: restarted
|
||||
@@ -0,0 +1,64 @@
|
||||
---
|
||||
# Nginx CDN Konfiguration
|
||||
|
||||
- name: Remove default nginx config
|
||||
file:
|
||||
path: /etc/nginx/sites-enabled/default
|
||||
state: absent
|
||||
notify: reload nginx
|
||||
|
||||
- name: Create nginx directories
|
||||
file:
|
||||
path: "{{ item }}"
|
||||
state: directory
|
||||
owner: www-data
|
||||
group: www-data
|
||||
mode: '0755'
|
||||
loop:
|
||||
- /var/cache/nginx/static
|
||||
- /var/cache/nginx/images
|
||||
- /var/cache/nginx/html
|
||||
- /var/log/nginx/cdn
|
||||
- /etc/nginx/includes
|
||||
|
||||
- name: Configure nginx main config
|
||||
template:
|
||||
src: nginx.conf.j2
|
||||
dest: /etc/nginx/nginx.conf
|
||||
backup: yes
|
||||
notify: reload nginx
|
||||
|
||||
- name: Create nginx includes
|
||||
template:
|
||||
src: "{{ item }}.j2"
|
||||
dest: "/etc/nginx/includes/{{ item }}"
|
||||
loop:
|
||||
- security-headers.conf
|
||||
- rate-limiting.conf
|
||||
- gzip-settings.conf
|
||||
notify: reload nginx
|
||||
|
||||
- name: Configure CDN site
|
||||
template:
|
||||
src: cdn-site.conf.j2
|
||||
dest: /etc/nginx/sites-available/cdn
|
||||
backup: yes
|
||||
notify: reload nginx
|
||||
|
||||
- name: Enable CDN site
|
||||
file:
|
||||
src: /etc/nginx/sites-available/cdn
|
||||
dest: /etc/nginx/sites-enabled/cdn
|
||||
state: link
|
||||
notify: reload nginx
|
||||
|
||||
- name: Test nginx configuration
|
||||
command: nginx -t
|
||||
register: nginx_test
|
||||
failed_when: nginx_test.rc != 0
|
||||
|
||||
- name: Start and enable nginx
|
||||
systemd:
|
||||
name: nginx
|
||||
state: started
|
||||
enabled: yes
|
||||
@@ -0,0 +1,195 @@
|
||||
server {
|
||||
listen 80;
|
||||
listen [::]:80;
|
||||
server_name {{ cdn_domain }};
|
||||
|
||||
# Redirect HTTP to HTTPS
|
||||
return 301 https://$server_name$request_uri;
|
||||
}
|
||||
|
||||
server {
|
||||
listen 443 ssl http2;
|
||||
listen [::]:443 ssl http2;
|
||||
server_name {{ cdn_domain }};
|
||||
|
||||
# SSL Configuration (wird von Certbot automatisch gefüllt)
|
||||
ssl_certificate /etc/letsencrypt/live/{{ cdn_domain }}/fullchain.pem;
|
||||
ssl_certificate_key /etc/letsencrypt/live/{{ cdn_domain }}/privkey.pem;
|
||||
include /etc/letsencrypt/options-ssl-nginx.conf;
|
||||
ssl_dhparam /etc/letsencrypt/ssl-dhparams.pem;
|
||||
|
||||
# CDN Headers
|
||||
add_header X-CDN-Node "{{ city }}, Deutschland";
|
||||
add_header X-Cache-Status $upstream_cache_status always;
|
||||
add_header X-Served-By "nginx-{{ inventory_hostname }}";
|
||||
|
||||
# Security Headers
|
||||
include /etc/nginx/includes/security-headers.conf;
|
||||
|
||||
# Logging
|
||||
access_log /var/log/nginx/cdn/{{ cdn_domain }}.access.log cdn_format;
|
||||
error_log /var/log/nginx/cdn/{{ cdn_domain }}.error.log warn;
|
||||
|
||||
# Rate Limiting
|
||||
include /etc/nginx/includes/rate-limiting.conf;
|
||||
|
||||
# Gzip Compression
|
||||
include /etc/nginx/includes/gzip-settings.conf;
|
||||
|
||||
# Nginx Status für Monitoring
|
||||
location /nginx_status {
|
||||
stub_status on;
|
||||
access_log off;
|
||||
allow 127.0.0.1;
|
||||
allow 10.0.0.0/8;
|
||||
deny all;
|
||||
}
|
||||
|
||||
##
|
||||
# Static Files (CSS, JS, Fonts) - Lange Cache-Zeit
|
||||
##
|
||||
location ~* \.(css|js|woff|woff2|ttf|eot|ico)$ {
|
||||
proxy_pass https://origin_servers;
|
||||
proxy_ssl_verify off;
|
||||
|
||||
# Cache Settings
|
||||
proxy_cache static_cache;
|
||||
proxy_cache_valid 200 302 {{ cache_settings.static_files_ttl }};
|
||||
proxy_cache_valid 404 1m;
|
||||
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
|
||||
proxy_cache_lock on;
|
||||
proxy_cache_revalidate on;
|
||||
|
||||
# Headers
|
||||
expires {{ cache_settings.static_files_ttl }};
|
||||
add_header Cache-Control "public, immutable";
|
||||
add_header Vary "Accept-Encoding";
|
||||
|
||||
# Rate Limiting
|
||||
limit_req zone=static_files burst=50 nodelay;
|
||||
|
||||
# Proxy Headers
|
||||
proxy_set_header Host {{ origin_domain }};
|
||||
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;
|
||||
}
|
||||
|
||||
##
|
||||
# Images - Mittlere Cache-Zeit
|
||||
##
|
||||
location ~* \.(jpg|jpeg|png|gif|webp|svg|avif|bmp|tiff)$ {
|
||||
proxy_pass https://origin_servers;
|
||||
proxy_ssl_verify off;
|
||||
|
||||
# Cache Settings
|
||||
proxy_cache images_cache;
|
||||
proxy_cache_valid 200 302 {{ cache_settings.images_ttl }};
|
||||
proxy_cache_valid 404 5m;
|
||||
proxy_cache_use_stale error timeout invalid_header updating http_500 http_502 http_503 http_504;
|
||||
|
||||
# Headers
|
||||
expires {{ cache_settings.images_ttl }};
|
||||
add_header Cache-Control "public";
|
||||
add_header Vary "Accept";
|
||||
|
||||
# Rate Limiting
|
||||
limit_req zone=images burst=30 nodelay;
|
||||
|
||||
# Proxy Headers
|
||||
proxy_set_header Host {{ origin_domain }};
|
||||
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 Endpoints - Kein Caching
|
||||
##
|
||||
location /api/ {
|
||||
proxy_pass https://origin_servers;
|
||||
proxy_ssl_verify off;
|
||||
|
||||
# Kein Caching
|
||||
proxy_no_cache 1;
|
||||
proxy_cache_bypass 1;
|
||||
add_header Cache-Control "no-cache, no-store, must-revalidate";
|
||||
add_header Pragma "no-cache";
|
||||
add_header Expires "0";
|
||||
|
||||
# Rate Limiting
|
||||
limit_req zone=api burst=10 nodelay;
|
||||
|
||||
# CORS Headers
|
||||
add_header Access-Control-Allow-Origin "https://{{ origin_domain }}";
|
||||
add_header Access-Control-Allow-Methods "GET, POST, PUT, DELETE, OPTIONS";
|
||||
add_header Access-Control-Allow-Headers "Authorization, Content-Type, X-Requested-With";
|
||||
add_header Access-Control-Allow-Credentials true;
|
||||
|
||||
# Proxy Headers
|
||||
proxy_set_header Host {{ origin_domain }};
|
||||
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;
|
||||
|
||||
# Timeouts
|
||||
proxy_connect_timeout {{ proxy_settings.connect_timeout }};
|
||||
proxy_send_timeout {{ proxy_settings.send_timeout }};
|
||||
proxy_read_timeout {{ proxy_settings.read_timeout }};
|
||||
}
|
||||
|
||||
##
|
||||
# Cache Purge (nur interne IPs)
|
||||
##
|
||||
location ~ /purge(/.*) {
|
||||
allow 127.0.0.1;
|
||||
allow 10.0.0.0/8;
|
||||
allow 192.168.0.0/16;
|
||||
deny all;
|
||||
|
||||
proxy_cache_purge static_cache $scheme$proxy_host$1;
|
||||
}
|
||||
|
||||
##
|
||||
# Health Check
|
||||
##
|
||||
location /health {
|
||||
access_log off;
|
||||
return 200 "OK - CDN Node {{ city }}\nRegion: {{ region }}\nTier: {{ tier }}\nTimestamp: $time_iso8601\n";
|
||||
add_header Content-Type text/plain;
|
||||
}
|
||||
|
||||
##
|
||||
# Default Location - HTML Caching
|
||||
##
|
||||
location / {
|
||||
proxy_pass https://origin_servers;
|
||||
proxy_ssl_verify off;
|
||||
|
||||
# Cache Settings für HTML
|
||||
proxy_cache html_cache;
|
||||
proxy_cache_valid 200 {{ cache_settings.html_ttl }};
|
||||
proxy_cache_valid 404 1m;
|
||||
proxy_cache_bypass $arg_nocache $cookie_sessionid $http_authorization;
|
||||
|
||||
# Headers
|
||||
add_header Cache-Control "public, max-age=300";
|
||||
|
||||
# Proxy Headers
|
||||
proxy_set_header Host {{ origin_domain }};
|
||||
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_set_header X-CDN-Node "{{ city }}";
|
||||
|
||||
# Timeouts
|
||||
proxy_connect_timeout {{ proxy_settings.connect_timeout }};
|
||||
proxy_send_timeout {{ proxy_settings.send_timeout }};
|
||||
proxy_read_timeout {{ proxy_settings.read_timeout }};
|
||||
|
||||
# Buffering
|
||||
proxy_buffering {{ proxy_settings.buffering }};
|
||||
proxy_buffer_size {{ proxy_settings.buffer_size }};
|
||||
proxy_buffers {{ proxy_settings.buffers }};
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
# Gzip Compression Settings
|
||||
|
||||
gzip on;
|
||||
gzip_vary on;
|
||||
gzip_min_length 1024;
|
||||
gzip_comp_level 6;
|
||||
gzip_proxied any;
|
||||
gzip_disable "msie6";
|
||||
|
||||
gzip_types
|
||||
text/plain
|
||||
text/css
|
||||
text/xml
|
||||
text/javascript
|
||||
application/javascript
|
||||
application/xml+rss
|
||||
application/atom+xml
|
||||
image/svg+xml
|
||||
application/json
|
||||
application/ld+json;
|
||||
@@ -0,0 +1,75 @@
|
||||
user www-data;
|
||||
worker_processes {{ nginx_worker_processes }};
|
||||
pid /run/nginx.pid;
|
||||
include /etc/nginx/modules-enabled/*.conf;
|
||||
|
||||
events {
|
||||
worker_connections {{ nginx_worker_connections }};
|
||||
use epoll;
|
||||
multi_accept on;
|
||||
}
|
||||
|
||||
http {
|
||||
##
|
||||
# Basic Settings
|
||||
##
|
||||
sendfile {{ tcp_optimizations.sendfile }};
|
||||
tcp_nopush {{ tcp_optimizations.tcp_nopush }};
|
||||
tcp_nodelay {{ tcp_optimizations.tcp_nodelay }};
|
||||
keepalive_timeout {{ nginx_keepalive_timeout }};
|
||||
types_hash_max_size 2048;
|
||||
server_tokens off;
|
||||
|
||||
server_names_hash_bucket_size 64;
|
||||
|
||||
include /etc/nginx/mime.types;
|
||||
default_type application/octet-stream;
|
||||
|
||||
##
|
||||
# DSGVO-konforme Logging
|
||||
##
|
||||
map $remote_addr $anonymized_ip {
|
||||
~(?P<ip>\d+\.\d+\.\d+)\.\d+ $ip.0;
|
||||
~(?P<ipv6>[^:]+:[^:]+:[^:]+:[^:]+):.* $ipv6::;
|
||||
default 0.0.0.0;
|
||||
}
|
||||
|
||||
log_format cdn_format '$anonymized_ip - $remote_user [$time_local] '
|
||||
'"$request" $status $body_bytes_sent '
|
||||
'"$http_referer" "$http_user_agent" '
|
||||
'rt=$request_time '
|
||||
'cache="$upstream_cache_status" '
|
||||
'cdn_node="{{ inventory_hostname }}"';
|
||||
|
||||
access_log /var/log/nginx/access.log cdn_format;
|
||||
error_log /var/log/nginx/error.log warn;
|
||||
|
||||
##
|
||||
# Cache Paths
|
||||
##
|
||||
proxy_cache_path /var/cache/nginx/static levels=1:2 keys_zone=static_cache:100m
|
||||
max_size={{ cache_size }} inactive=7d use_temp_path=off;
|
||||
proxy_cache_path /var/cache/nginx/images levels=1:2 keys_zone=images_cache:100m
|
||||
max_size={{ cache_size }} inactive=30d use_temp_path=off;
|
||||
proxy_cache_path /var/cache/nginx/html levels=1:2 keys_zone=html_cache:50m
|
||||
max_size=5g inactive=1h use_temp_path=off;
|
||||
|
||||
##
|
||||
# Upstream zu Origin-Servern
|
||||
##
|
||||
upstream origin_servers {
|
||||
{% for host in groups['origin_servers'] %}
|
||||
server {{ hostvars[host]['ansible_default_ipv4']['address'] }}:443
|
||||
weight=1 max_fails=3 fail_timeout=30s;
|
||||
{% endfor %}
|
||||
keepalive 32;
|
||||
keepalive_requests 1000;
|
||||
keepalive_timeout 60s;
|
||||
}
|
||||
|
||||
##
|
||||
# Include configurations
|
||||
##
|
||||
include /etc/nginx/includes/*.conf;
|
||||
include /etc/nginx/sites-enabled/*;
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
# Rate Limiting Zones
|
||||
|
||||
limit_req_zone $binary_remote_addr zone=api:10m rate={{ rate_limits.api }};
|
||||
limit_req_zone $binary_remote_addr zone=static_files:10m rate={{ rate_limits.static }};
|
||||
limit_req_zone $binary_remote_addr zone=images:10m rate={{ rate_limits.images }};
|
||||
|
||||
# Connection Limiting
|
||||
limit_conn_zone $binary_remote_addr zone=perip:10m;
|
||||
limit_conn perip 10;
|
||||
@@ -0,0 +1,10 @@
|
||||
# Security Headers für CDN
|
||||
|
||||
add_header X-Frame-Options "SAMEORIGIN" 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 Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
|
||||
|
||||
# DSGVO Header
|
||||
add_header X-Data-Processing "Art. 6 Abs. 1 lit. f DSGVO" always;
|
||||
@@ -0,0 +1,29 @@
|
||||
---
|
||||
# Einfaches Monitoring ohne Prometheus
|
||||
|
||||
- name: Create simple monitoring script
|
||||
template:
|
||||
src: simple-monitor.sh.j2
|
||||
dest: /usr/local/bin/cdn-monitor
|
||||
mode: '0755'
|
||||
|
||||
- name: Setup monitoring cron job
|
||||
cron:
|
||||
name: "CDN Health Monitor"
|
||||
minute: "*/5"
|
||||
job: "/usr/local/bin/cdn-monitor"
|
||||
user: root
|
||||
|
||||
- name: Create log rotation for monitoring logs
|
||||
copy:
|
||||
content: |
|
||||
/var/log/nginx/cdn-monitor.log {
|
||||
weekly
|
||||
missingok
|
||||
rotate 4
|
||||
compress
|
||||
delaycompress
|
||||
notifempty
|
||||
}
|
||||
dest: /etc/logrotate.d/cdn-monitor
|
||||
mode: '0644'
|
||||
@@ -0,0 +1,71 @@
|
||||
#!/bin/bash
|
||||
# Einfaches CDN Monitoring für {{ inventory_hostname }}
|
||||
|
||||
LOG_FILE="/var/log/nginx/cdn-monitor.log"
|
||||
TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
|
||||
CDN_DOMAIN="{{ cdn_domain }}"
|
||||
|
||||
# Health Check
|
||||
health_check() {
|
||||
local response=$(curl -s -o /dev/null -w "%{http_code}" "https://$CDN_DOMAIN/health")
|
||||
|
||||
if [ "$response" = "200" ]; then
|
||||
echo "[$TIMESTAMP] ✅ Health check OK" >> $LOG_FILE
|
||||
return 0
|
||||
else
|
||||
echo "[$TIMESTAMP] ❌ Health check FAILED (HTTP $response)" >> $LOG_FILE
|
||||
return 1
|
||||
fi
|
||||
}
|
||||
|
||||
# Nginx-Statistiken
|
||||
nginx_stats() {
|
||||
local stats=$(curl -s http://127.0.0.1/nginx_status 2>/dev/null)
|
||||
if [ $? -eq 0 ]; then
|
||||
local active_conn=$(echo "$stats" | grep "Active connections" | awk '{print $3}')
|
||||
local total_requests=$(echo "$stats" | grep "server accepts" | awk '{print $3}')
|
||||
echo "[$TIMESTAMP] 📊 Active: $active_conn, Total: $total_requests" >> $LOG_FILE
|
||||
fi
|
||||
}
|
||||
|
||||
# Cache-Größe prüfen
|
||||
cache_check() {
|
||||
local cache_size=$(du -sh /var/cache/nginx/ 2>/dev/null | cut -f1)
|
||||
local cache_files=$(find /var/cache/nginx/ -type f 2>/dev/null | wc -l)
|
||||
echo "[$TIMESTAMP] 💾 Cache: $cache_size ($cache_files files)" >> $LOG_FILE
|
||||
}
|
||||
|
||||
# System-Ressourcen
|
||||
system_check() {
|
||||
local load=$(uptime | awk -F'load average:' '{print $2}' | awk -F',' '{print $1}' | tr -d ' ')
|
||||
local memory=$(free | grep Mem | awk '{printf "%.1f", $3/$2 * 100.0}')
|
||||
local disk=$(df / | tail -1 | awk '{print $5}' | sed 's/%//')
|
||||
|
||||
echo "[$TIMESTAMP] 🖥️ Load: $load, Memory: ${memory}%, Disk: ${disk}%" >> $LOG_FILE
|
||||
|
||||
# Warnungen bei hoher Auslastung
|
||||
if (( $(echo "$load > 5.0" | bc -l 2>/dev/null || echo 0) )); then
|
||||
echo "[$TIMESTAMP] ⚠️ HIGH LOAD WARNING: $load" >> $LOG_FILE
|
||||
fi
|
||||
|
||||
if (( $(echo "$memory > 90.0" | bc -l 2>/dev/null || echo 0) )); then
|
||||
echo "[$TIMESTAMP] ⚠️ HIGH MEMORY WARNING: ${memory}%" >> $LOG_FILE
|
||||
fi
|
||||
|
||||
if [ "$disk" -gt 85 ]; then
|
||||
echo "[$TIMESTAMP] ⚠️ HIGH DISK USAGE WARNING: ${disk}%" >> $LOG_FILE
|
||||
fi
|
||||
}
|
||||
|
||||
# Hauptausführung
|
||||
main() {
|
||||
health_check
|
||||
nginx_stats
|
||||
cache_check
|
||||
system_check
|
||||
|
||||
# Log-Datei begrenzen (nur letzte 1000 Zeilen behalten)
|
||||
tail -n 1000 $LOG_FILE > ${LOG_FILE}.tmp && mv ${LOG_FILE}.tmp $LOG_FILE
|
||||
}
|
||||
|
||||
main
|
||||
@@ -0,0 +1,30 @@
|
||||
---
|
||||
# SSL-Zertifikate mit Let's Encrypt
|
||||
|
||||
- name: Check if certificate exists
|
||||
stat:
|
||||
path: "/etc/letsencrypt/live/{{ cdn_domain }}/fullchain.pem"
|
||||
register: cert_exists
|
||||
|
||||
- name: Generate SSL certificate with certbot
|
||||
command: >
|
||||
certbot certonly --nginx
|
||||
-d {{ cdn_domain }}
|
||||
--non-interactive
|
||||
--agree-tos
|
||||
--email {{ ssl_email }}
|
||||
when: not cert_exists.stat.exists
|
||||
|
||||
- name: Setup SSL certificate renewal
|
||||
cron:
|
||||
name: "Renew SSL certificates"
|
||||
minute: "0"
|
||||
hour: "3"
|
||||
job: "certbot renew --quiet --deploy-hook 'systemctl reload nginx'"
|
||||
user: root
|
||||
|
||||
- name: Test SSL certificate renewal (dry-run)
|
||||
command: certbot renew --dry-run
|
||||
register: renewal_test
|
||||
failed_when: renewal_test.rc != 0
|
||||
changed_when: false
|
||||
Reference in New Issue
Block a user