<IfModule mod_ssl.c>
<VirtualHost *:443>
    ServerName track.rosille.com.ng
    DocumentRoot /var/www/track

    <Directory /var/www/track>
        AllowOverride All
        Require all granted
    </Directory>

    ErrorLog ${APACHE_LOG_DIR}/track-error.log
    CustomLog ${APACHE_LOG_DIR}/track-access.log combined

    SSLEngine on
    SSLCertificateFile /etc/letsencrypt/live/track.rosille.com.ng/fullchain.pem
    SSLCertificateKeyFile /etc/letsencrypt/live/track.rosille.com.ng/privkey.pem

    ProxyPreserveHost On

    # Forwarded headers for Traccar to detect HTTPS
    RequestHeader set X-Forwarded-Proto "https"
    RequestHeader set X-Forwarded-Port "443"

    # --------------------------------------------------------
    # Reverse proxy — all traffic goes to Traccar
    # --------------------------------------------------------
    ProxyPass / http://127.0.0.1:8082/
    ProxyPassReverse / http://127.0.0.1:8082/

    # --------------------------------------------------------
    # WebSocket Support (live device updates)
    # --------------------------------------------------------
    RewriteEngine On
    RewriteCond %{HTTP:Upgrade} =websocket [NC]
    RewriteRule /(.*) ws://127.0.0.1:8082/$1 [P,L]

    # --------------------------------------------------------
    # SSL Configuration
    # --------------------------------------------------------
    Include /etc/letsencrypt/options-ssl-apache.conf
</VirtualHost>
</IfModule>
