<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

    ProxyPreserveHost On
    ProxyRequests Off
    AllowEncodedSlashes NoDecode

    <Proxy *>
        Require all granted
    </Proxy>

    # WebSocket support (MUST be before main proxy)
    ProxyPass /ws ws://127.0.0.1:5678/ws
    ProxyPassReverse /ws ws://127.0.0.1:5678/ws
    
    # n8n push endpoint (used for real-time WebSocket)
ProxyPass /rest/push ws://127.0.0.1:5678/rest/push
ProxyPassReverse /rest/push ws://127.0.0.1:5678/rest/push


    # Main n8n application proxy
    ProxyPass / http://127.0.0.1:5678/
    ProxyPassReverse / http://127.0.0.1:5678/

    ErrorLog ${APACHE_LOG_DIR}/agents_error.log
    CustomLog ${APACHE_LOG_DIR}/agents_access.log combined
</VirtualHost>

