Custom Domain

Luis Fernando 6 months ago

Hello,
I successful to run traccar on a VPS in OVHcloud, it's accessible through the IP address, e.g., 123.45.678.900:8082, what I want to do is to change the ip address to www.my-domaine-name.com. I added an A record with my server IP address as a value. But it's not working. Help me please.

Anton Tananaev6 months ago

Are you using the right port?

odhiambo6 months ago

The A record alone will not work. You have to run a web server (Apache or Nginx) to handle the name. I do this with Apache like this:

# traccar vhost

<VirtualHost *:80>
    ServerName www.my-domaine-name.com
    ServerAdmin me@my-domaine-name.com

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://www.my-domaine-name.com/$1 [L,R=301]

</VirtualHost>

# SSL Site

<VirtualHost *:443>
    ServerAdmin me@my-domaine-name.com
    ServerName www.my-domaine-name.com

    SSLEngine on
    SSLCipherSuite ALL:!ADH:!EXPORT56:RC4+RSA:+HIGH:+MEDIUM:+LOW:+SSLv2:+EXP:+eNULL
    SSLCertificateFile "/usr/local/etc/letsencrypt/live/www.my-domaine-name.com/fullchain.pem"
    SSLCertificateKeyFile "/usr/local/etc/letsencrypt/live/www.my-domaine-name.com/privkey.pem"
    SSLCACertificatePath  "/usr/local/etc/letsencrypt/live/www.my-domaine-name.com"

    CustomLog /var/log/apache2/traccar-access.log combined
    ErrorLog  /var/log/apache2/traccar-error.log
    LogFormat "%h %l %u %t %{Host}i \"%r\" %>s %b \"%{Referer}i\" \"%{User-Agent}i\" %V %p" combined

    ProxyPass /api/socket ws://localhost:8082/api/socket
    ProxyPassReverse /api/socket ws://localhost:8082/api/socket
    ProxyPass "/"  "http://localhost:8082/"
    ProxyPassReverse "/"  "http://localhost:8082/"
</VirtualHost>

And in conf/traccar.xml, I also added these below, because I only want traccar to bind to localhost (127.0.0.1), and for password recovery, I want it to use my domain name.

<entry key='web.address'>127.0.0.1</entry>
<entry key='web.url'>https://www.my-domaine-name.com</entry>

HTH

Anton Tananaev6 months ago

The A record alone will not work.

This is false information. A domain can work directly with Traccar. You only need Apache or another proxy if you want HTTPS.

odhiambo6 months ago

Aha!
So all he has to do is to configure the hostname on the host to match the A record and that's it? Seeing as his question meant that he only wanted to put http://www.my-domaine-name.com in the browser (without appending the port) to access traccar, then he will also need to use:

<entry key='web.port'>80</entry>

Unless I misunderstood his requirement.

I think https should be mandatory these days though :)

Luis Fernando 6 months ago

Yes, I only want to put http://www.my-domaine-name.com in the browser (without appending the port) to access traccar.
Where I can change this values (hostname and web.port)? In the traccar.xml file?

Anton Tananaev6 months ago

You only need to change port in the configuration file. Make sure you check the official documentation before asking for additional help.

Luis Fernando 6 months ago

I was able to solve my problem, I did everything odhiambo said (run the web server), thanks to both. :)