Course content
Back to course
Secure Connection for Traccar HTTPS
Traccar does not natively support secure connections, so a proxy server is used, in this case Apache, to tunnel all requests through a secure connection.
Emmanuel Díaz Leal Hernández
May 25, 2024
Intermediate
Traccar serves the web interface and API using regular HTTP. To enable HTTPS, a proxy server like Apache is used.
Apache Installation
Install and enable necessary modules:
sudo add-apt-repository ppa:ondrej/apache2 sudo apt-get install ssl-cert apache2 sudo a2enmod ssl proxy_http proxy_wstunnel rewrite sudo service apache2 restartConfigure Apache:
sudo nano /etc/apache2/sites-available/traccar.conf<VirtualHost *:80> ServerName demo.traccar.org Redirect / https://demo.traccar.org/ </VirtualHost> <IfModule mod_ssl.c> <VirtualHost _default_:443> ServerName demo.traccar.org ServerAdmin webmaster@localhost DocumentRoot /var/www/html ProxyPass /api/socket ws://localhost:8082/api/socket ProxyPassReverse /api/socket ws://localhost:8082/api/socket ProxyPass / http://localhost:8082/ ProxyPassReverse / http://localhost:8082/ SSLEngine on SSLCertificateFile /etc/ssl/certs/ssl-cert-snakeoil.pem SSLCertificateKeyFile /etc/ssl/private/ssl-cert-snakeoil.key </VirtualHost> </IfModule>Enable new configuration:
sudo a2dissite 000-default sudo a2ensite traccar sudo service apache2 restartGenerate SSL certificate with Let's Encrypt:
sudo apt install certbot python3-certbot-apache sudo certbot --apache
Traccar in Subdirectory
Adjust the proxy and cookies configuration:
ProxyRequests off
ProxyPass /gps/api/socket ws://localhost:8082/api/socket
ProxyPassReverse /gps/api/socket ws://localhost:8082/api/socket
ProxyPass /gps/ http://localhost:8082/
ProxyPassReverse /gps/ http://localhost:8082/
ProxyPassReverseCookiePath / /gps/
Redirect permanent /gps /gps/