# Standard Nginx User
user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log notice;
pid /var/run/nginx.pid;

# Worker-Prozess-Einstellungen
events {
    worker_connections 1024;
    use epoll;
    multi_accept on;
}

http {
    # MIME-Types
    include /etc/nginx/mime.types;
    default_type application/octet-stream;

    # Server-Tokens für Sicherheit ausblenden
    server_tokens off;

    # Rate-Limiting
    limit_req_zone $binary_remote_addr zone=mylimit:10m rate=10r/s;

    # Logging-Format
    log_format main '$remote_addr - $remote_user [$time_local] "$request" '
                    '$status $body_bytes_sent "$http_referer" '
                    '"$http_user_agent" "$http_x_forwarded_for" '
                    'rt=$request_time uct="$upstream_connect_time" '
                    'uht="$upstream_header_time" urt="$upstream_response_time"';

    # Container-optimierte Logs
    access_log /dev/stdout main;
    error_log /dev/stderr warn;

    # Performance-Optimierungen
    sendfile on;
    tcp_nopush on;
    tcp_nodelay on;
    keepalive_timeout 65;
    types_hash_max_size 2048;
    client_max_body_size 64M;

    # Gzip-Kompression
    gzip on;
    gzip_vary on;
    gzip_min_length 1024;
    gzip_proxied any;
    gzip_comp_level 6;
    gzip_types
        text/plain
        text/css
        text/xml
        text/javascript
        application/json
        application/javascript
        application/xml+rss
        application/atom+xml
        image/svg+xml
        application/rss+xml
        application/vnd.ms-fontobject
        application/x-font-ttf
        font/opentype;

    # Basis-Sicherheits-Header
    add_header X-Frame-Options "SAMEORIGIN" always;
    add_header X-XSS-Protection "1; mode=block" always;
    add_header X-Content-Type-Options "nosniff" always;
    add_header Referrer-Policy "no-referrer-when-downgrade" always;

    # SSL-Session-Cache
    ssl_session_cache shared:SSL:10m;
    ssl_session_timeout 10m;
    ssl_session_tickets off;

    # Server-Konfigurationen einbinden
    include /etc/nginx/conf.d/*.conf;
}
