<VirtualHost *:80>
    ServerName agents.wifimtaani.top
    Redirect permanent / https://agents.wifimtaani.top/
</VirtualHost>

<VirtualHost *:443>
    ServerName agents.wifimtaani.top

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/agents.wifimtaani.top/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/agents.wifimtaani.top/privkey.pem

    # WebSocket support
    RewriteEngine on
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule /(.*) ws://localhost:5678/$1 [P,L]

    ProxyPreserveHost On
    ProxyRequests Off
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-Host "agents.wifimtaani.top"

    ProxyPass / http://localhost:5678/
    ProxyPassReverse / http://localhost:5678/

    ErrorLog ${APACHE_LOG_DIR}/n8n_error.log
    CustomLog ${APACHE_LOG_DIR}/n8n_access.log combined
</VirtualHost>

