Server status shows Offline Using Nginx proxy url

tecseguridada year ago

Hello, when I log into the Traccar 5.6 platform using the URL with a proxy in the "server information," it shows as offline, but if I log in directly using http://url:8082, it appears as online. What could be the issue? Can someone share their Nginx configuration with me to compare if I'm missing something? There are no connection or socket errors shown, but it seems to generate small intermittent errors in the statuses.

PD: Should the Nginx configuration for Traccar 4.x be different from that of 5.x?

Im using
Ubuntu 22.04
Nginx
Traccar 5.6

Anton Tananaeva year ago

What are the errors? It sounds like WebSocket is not connected. Have you enabled proxy for the WebSocket? Maybe you can share details on your configuration.

tecseguridada year ago

Hello Anton It's not giving me any noticeable code errors.

Here is my config.

location /api/socket {
       include proxy_params;
       proxy_http_version 1.1;
       proxy_cache_bypass $http_upgrade;
       proxy_buffering off;
       proxy_set_header Host $host;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "Upgrade";
       proxy_pass http://localhost:8082/api/socket;

    }

    location / {
       proxy_set_header X-Forwarded-Host $host:$server_port;
       proxy_set_header X-Forwarded-Server $host;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

       proxy_pass http://localhost:8082/;
    }
Anton Tananaeva year ago

Have you checked the developer tools for errors?

tecseguridada year ago

You are right give me:

   WebSocket connection to 'wss://deltageos.cl/api/socket' failed:           SocketController.js:36 

but the same configuration in version 4.x does not throw any errors

Anton Tananaeva year ago

WebSocket connection is the same for both versions.

tecseguridada year ago

So I don't understand why it's not connecting, if I open the URL without a proxy, that is, http:/url:8082, it connects without errors. Status 'Server Online'. :-(

Track-tracea year ago

You use an SSL cert for this connection ? : WebSocket connection to 'wss://deltageos.cl/api/socket' failed: SocketController.js:36

Since wss:// is ssl/tls connection over that socket

tecseguridada year ago

Hi Track, yes i use a ssl cert, maybe i have a config problem. :-/

Track-tracea year ago

Ok, so what is your nginx ssl config for that domain ?

tecseguridada year ago

This is the full config

location /api/socket {
       include proxy_params;
       proxy_http_version 1.1;
       proxy_cache_bypass $http_upgrade;
       proxy_buffering off;
       proxy_set_header Host $host;
       proxy_set_header Upgrade $http_upgrade;
       proxy_set_header Connection "Upgrade";
       proxy_pass http://localhost:8082/api/socket;

    }

    location / {
       proxy_set_header X-Forwarded-Host $host:$server_port;
       proxy_set_header X-Forwarded-Server $host;
       proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;

       proxy_pass http://localhost:8082/;
    }

    
    listen 85.239.248.228:443 ssl;
    ssl_certificate /etc/ssl/virtualmin/167480878579088/ssl.combined;
    ssl_certificate_key /etc/ssl/virtualmin/167480878579088/ssl.key;
    if ($scheme = http) {
        rewrite "^/(?!.well-known)(.*)$" "https://$host/$1" break;
    }
tecseguridada year ago

Thank you very much for your help, I solved it by applying the following proxy configuration.

location / {
        proxy_pass http://127.0.0.1:8082;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
location /api/socket {
        proxy_pass http://localhost:8082/api/socket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection "upgrade";
    }
Track-tracea year ago

Good that you post your solution here.

It would be good that you check your other nginx config also. Since there is some access that you should not like.

For instance: unsecure http://85.239.248.228/login
For instance: unsecure https://85.239.248.228/login

I also wonder why you use listen 85.239.248.228:443 ssl; in your nginx config.
Normally you would listen for the qualified domain name.

Track-tracea year ago

What happens when you add this below listen 85.239.248.228:443 ssl;

server_name 85.239.248.228;
return 301 https://deltageos.cl;

tecseguridada year ago

Thank you for the observation, but it's actually an automatic configuration generated by Virtualmin. If possible, what would be your suggestion for correcting this?