Nginx on subdomain with Docker, update on position with delay

IoSonoPiero7 months ago

Hello people,
I have a strange issue that I'll try to explain.
I'm not an expert, so please don't blame me.

I run an instance of Traccar on a web server, and it works very well.
It has Apache (for SSL) and Mysql.

Now, I want to migrate to my home server.
I use Docker, with Nginx, for reverse proxy.
I used Traccar with Mysql in Docker, too.

With this second solution, the update of my device is about every 60 seconds, so it's now very nice to see my car being "teleported".
The following is the fragment of my nginx.conf:

# HTTPS server for Traccar
server {
    listen 443 ssl;
    server_name traccar.mydomain.com;

    ssl_certificate /etc/nginx/certs/live/mydomain.com/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/live/mydomain.com/privkey.pem;

    location / {
        proxy_pass http://192.168.1.41:8082;
        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;
    }
}

Does anybody have a working version of Traccar on a subdomain with Nginx?
Someone can help, please?

Anton Tananaev7 months ago

I'm pretty sure there are some examples on the forum.

IoSonoPiero7 months ago

Hello,
Before posting, I did a few searches in the forum and got Apache-related discussions and some very old posts about Nginx.
Every time I tried modifying the config file, I had to go out and try it to work.

I'm not an expert, so I cannot go alone in web server configuration.

Anton Tananaev7 months ago

You're saying you're not an expert, but you still insist on using nginx when you actually have working Apache configuration? This doesn't really make sense to me.

IoSonoPiero7 months ago

You got right,
I forgot to mention one, or better, two important things.
I'm experimenting with Docker and Nginx was what I found first.
Apache on the web server is on second level domain, on my own server I need to use 3rd level domain.

Anton Tananaev7 months ago

It still doesn't explain why you can't do the same Apache setup.

IoSonoPiero7 months ago

Anton, I'm using Docker and Nginx to learn and experiment. I understand Apache might be simpler for some, but I'm trying to broaden my skills. If you have any specific suggestions or configurations for Nginx that could help, I'd really appreciate it. Not everyone is as experienced as you, but I'm doing my best to learn. Thanks!

Anton Tananaev7 months ago

If the goal is to learn, it probably make sense to study nginx documentation. It's not really something specific to Traccar.

IoSonoPiero7 months ago

Ok, thanks.

I hope someone other can contribute to this discussion too.

IoSonoPiero7 months ago

Hello people,
After some tests, I can confirm that the data sent by GPS are ALL captured by the server with Nginx.

In my Teltonika device, I use the Duplicate function, so data is sent simultaneously using TCP to my remote and local servers.

Comparing the log, the capture rate is equal between the remote-hosted version and the version on my local server.
So, no single package of information is lost.
This is good.

So, the only thing I need to understand is related to the update "speed" on the map.
It is continuous on the remote server; on the local server, it occurs every (about) 60 seconds.

I'll keep posting if something new is found.

Traccar is one of the best projects I've ever met. Period.

IoSonoPiero7 months ago

On the Developer Console, it shows this:

Schermata_20240531_093140.png

I'll try to investigate more.

IoSonoPiero7 months ago

Hello people,
I think I've solved it.

If someone needs the info, I'm posting here the fragment of the Nginx configuration for Traccar that is hosted on a subdomain.

# HTTPS server for Traccar
server {
    listen 443 ssl;
    server_name traccar.xxx.com;

    ssl_certificate /etc/nginx/certs/live/xxx.com/fullchain.pem;
    ssl_certificate_key /etc/nginx/certs/live/xxx.com/privkey.pem;

    location / {
        proxy_pass http://192.168.1.41:8082;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
        proxy_set_header Host $host;

        # Aggiungi le direttive seguenti per WebSocket
        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;
    }
}

Have fun with Traccar!