All posts
TraccarNginxSSLLinux

Traccar with Nginx and a free SSL certificate (Let's Encrypt)

Nov 15, 20264 min read

Out of the box, Traccar serves its web interface on http://your-server-ip:8082. That's fine for a quick test, but not for real use:

  • Logins and live locations travel over plain HTTP, so anyone on the network path can read them.
  • Phone apps and browsers increasingly refuse or warn about non-HTTPS sites.
  • Customers see an IP address and port instead of your brand.

The standard fix is to put Nginx in front of Traccar as a reverse proxy, on your own domain, with a free Let's Encrypt certificate. This post walks through it on Ubuntu.

What you need

  • A server running Traccar (web interface on port 8082, the default)
  • A domain or subdomain, e.g. track.example.com, with an A record pointing to the server's IP
  • SSH access with sudo

Check the DNS before starting. This should print your server's IP:

dig +short track.example.com

1. Install Nginx and Certbot

sudo apt update
sudo apt install -y nginx certbot python3-certbot-nginx

2. Create the Nginx site

Create /etc/nginx/sites-available/traccar:

server {
    listen 80;
    server_name track.example.com;

    location / {
        proxy_pass http://127.0.0.1:8082;
        proxy_http_version 1.1;

        # Live updates in the web UI use a WebSocket at /api/socket
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";

        proxy_set_header Host $host;
        proxy_set_header X-Real-IP $remote_addr;
        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
        proxy_set_header X-Forwarded-Proto $scheme;

        # Keep the WebSocket open; the map stops updating if it's cut off
        proxy_read_timeout 86400s;
    }
}

The Upgrade and Connection lines matter. Without them the page loads, but devices never move on the map until you refresh, because Traccar pushes live positions over a WebSocket. This is the most common mistake in Traccar proxy setups.

Enable the site and reload Nginx:

sudo ln -s /etc/nginx/sites-available/traccar /etc/nginx/sites-enabled/
sudo nginx -t
sudo systemctl reload nginx

Open http://track.example.com and you should see the Traccar login page.

3. Get the free SSL certificate

sudo certbot --nginx -d track.example.com

Certbot asks for an email address (for expiry warnings), gets the certificate, and edits the Nginx config to serve HTTPS. When it offers to redirect HTTP to HTTPS, say yes.

Renewal is automatic. Certbot installs a timer that renews certificates before they expire. Test that renewal will work:

sudo certbot renew --dry-run

4. Close port 8082 to the internet

Traccar is now reachable through Nginx on 443, so nobody should reach port 8082 directly. Otherwise people can bypass HTTPS.

The cleanest way is to make Traccar's web server listen only on localhost. In /opt/traccar/conf/traccar.xml, add:

<entry key='web.address'>127.0.0.1</entry>

Then restart Traccar:

sudo systemctl restart traccar

Also set the firewall so only what's needed is open. Keep your device protocol ports open (for example 5055 for OsmAnd/Traccar Client, 5027 for Teltonika, 5023 for GT06), because trackers connect to those directly, not through Nginx:

sudo ufw allow OpenSSH
sudo ufw allow 'Nginx Full'
sudo ufw allow 5055
sudo ufw allow 5027
sudo ufw enable
sudo ufw status

Check from your own computer that http://your-server-ip:8082 no longer loads, and that https://track.example.com does.

5. Tell Traccar its public address

Traccar puts links in emails (password resets, notifications). Set its public URL so those links use your domain:

<entry key='web.url'>https://track.example.com</entry>

Restart Traccar again after changing the config.

6. Update apps and users

  • In the Traccar Manager app or your own app, change the server URL to https://track.example.com.
  • Phones running Traccar Client send positions to the device port (e.g. http://track.example.com:5055), not the web address, so they keep working. If you want those uploads encrypted too, you can add a second Nginx site or location that proxies HTTPS to port 5055.

Troubleshooting

Symptom Likely cause
502 Bad Gateway Traccar isn't running, or isn't on 127.0.0.1:8082. Check sudo systemctl status traccar.
Map doesn't update until refresh Missing Upgrade/Connection headers or a short proxy_read_timeout
Certbot fails DNS doesn't point to this server yet, or port 80 is blocked
Devices stopped reporting A device port was closed by the firewall. Re-open it with ufw allow.
Email links show the IP address web.url not set or Traccar not restarted

Summary

  1. Point a domain at your server.
  2. Install Nginx and proxy to 127.0.0.1:8082, including the WebSocket headers.
  3. Run Certbot for a free certificate with automatic renewal.
  4. Bind Traccar's web server to localhost and firewall everything except SSH, 80/443 and device ports.
  5. Set web.url and update your apps.

If you'd rather have this done for you, along with MySQL, backups and your first devices connected, see my Traccar installation and setup service.

Keep reading

Need help with your Traccar server?

I offer Traccar setup and maintenance, GPS tracking apps and Flutter development.