server {
    listen 80;
    server_name teleflow.yourdomain.com;
    root /path/to/teleflow-crm/public;

    index index.php;

    charset utf-8;

    # Security headers
    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;

    # Redirect to installer if not installed
    location / {
        if (!-f $document_root/../storage/app/installed.lock) {
            rewrite ^.*$ /install.php last;
        }
        try_files $uri $uri/ /index.php?$query_string;
    }

    # PHP handler
    location ~ \.php$ {
        fastcgi_pass unix:/var/run/php/php8.3-fpm.sock;
        fastcgi_index index.php;
        fastcgi_param SCRIPT_FILENAME $realpath_root$fastcgi_script_name;
        include fastcgi_params;

        fastcgi_read_timeout 300;
        fastcgi_buffer_size 128k;
        fastcgi_buffers 4 256k;
        fastcgi_busy_buffers_size 256k;
    }

    # Deny access to hidden files
    location ~ /\. {
        deny all;
    }

    # Deny access to sensitive files
    location ~* (composer\.(json|lock)|package\.json|\.env)$ {
        deny all;
    }

    # Upload limits
    client_max_body_size 50M;

    # Static file caching
    location ~* \.(jpg|jpeg|png|gif|ico|css|js|svg|woff|woff2|ttf|eot)$ {
        expires 1y;
        add_header Cache-Control "public, immutable";
    }

    # Logging
    error_log /var/log/nginx/teleflow-error.log;
    access_log /var/log/nginx/teleflow-access.log;
}

# SSL configuration (recommended)
# server {
#     listen 443 ssl http2;
#     server_name teleflow.yourdomain.com;
#
#     ssl_certificate /path/to/ssl/cert.pem;
#     ssl_certificate_key /path/to/ssl/key.pem;
#
#     # Include all settings from above
# }
