WSS error

juanmales2 years ago

Hi,
Im trying to connect with api/socket using wss.
This is my nginx configuration:

server {
        listen xxx ssl;

        server_name xxx;

        ssl on;
        ssl_certificate             /usr/local/psa/var/certificates/scfLufbp0;
        ssl_certificate_key         /usr/local/psa/var/certificates/scfLufbp0;

        client_max_body_size 134217728;

        location / {
                proxy_pass http://127.0.0.1:8082; 
                proxy_hide_header upgrade;
                proxy_http_version 1.1;
                proxy_set_header Host             $host;
                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";

                proxy_redirect http://127.0.0.1:8082/ /;
                proxy_redirect ws://127.0.0.1:8082/api/socket /api/socket;
                allow all;

                proxy_connect_timeout 300;
                proxy_send_timeout 300;
                proxy_read_timeout 300;
        }
}
server {
  listen xxx:80;

        server_name xxx;

        client_max_body_size 134217728;

        location / {
                return 301 https://$host$request_uri;
       }
}

When I try to connect, the console return the next message:

posicion:739 WebSocket connection to 'wss://gpshermes.82-223-98-125.plesk.page/api/socket' failed:

juanmales2 years ago

I solved the problem, to anyone who needs help. My new nginx config:

upstream gps {
        server 127.0.0.1:8082;
}

server {
        listen xxx ssl;

        server_name xxx;

        ssl on;
        ssl_certificate             /usr/local/psa/var/certificates/scfLufbp0;
        ssl_certificate_key         /usr/local/psa/var/certificates/scfLufbp0;

        client_max_body_size 134217728;

        location / {
                proxy_pass http://gps/;

                proxy_http_version 1.1;
                proxy_set_header Host             $host;

                proxy_set_header X-Forwarded-Server $host;
                proxy_set_header X-Forwarded-Host $host;
                proxy_set_header X-Forwarded-For  $proxy_add_x_forwarded_for;
                proxy_set_header X_Real_IP $remote_addr;
                proxy_set_header X_Forwarded_Proto $scheme;
                proxy_set_header Upgrade $http_upgrade;
                proxy_set_header Connection "Upgrade";
                proxy_set_header Proxy "";

                proxy_pass_request_headers on;
                proxy_connect_timeout 300;
                proxy_send_timeout 300;
                proxy_read_timeout 300;
        }

}
server {
        listen xxx:80;

        server_name xxx;

        client_max_body_size 134217728;

        location / {
                return 301 https://$host$request_uri;
        }
}
Track-trace2 years ago

How about this config when the actual traccar server is on the same local lan but not on the same server as the Nginx proxy.
Tried both but still wss error. Even though i pointed the upstream server to traccar server ip and port on local lan.

Anton Tananaev2 years ago

There should be no difference whether it's local or not. If it doesn't work, maybe WebSocket is blocked on your network?