Websockets through proxy returning 401 on raspberry pi

All the topics related to QLC+ on the Raspberry Pi
Post Reply
joshiwoshi2005
Posts: 6
Joined: Mon Jan 07, 2019 2:15 pm
Real Name: Joshua Sanderson

Hi,

I hope I have come to the right place!

I am using NGINX (on another machine) to reverse proxy QLC's websocket on the raspberry using this configuration:

Code: Select all

location / {
	proxy_pass   http://192.168.*.*:9999;
	proxy_http_version 1.1;
	proxy_set_header Upgrade $http_upgrade;
	proxy_set_header Connection "Upgrade";
	proxy_set_header Host $host;
         proxy_read_timeout 999999999;
It works fine on a web browser, when I visit a small script I made and also through the QLC web API test ( https://www.qlcplus.org/Test_Web_API.html ), I had to download the html file first though, as the operation was deemed not secure by firefox, because the webpage was loaded in HTTPS and the websocket was not wss.

But when I try and run a python (or Node.js) file, I am situated with a 401 error message:

Code: Select all

websocket._exceptions.WebSocketBadStatusException: Handshake status 401 Unauthorized
I also tried directly connecting to the raspberry pi's local IP, but it has the same outcome

Any ideas how I can fix this? Let me know if you need any other information!

Thanks
lighthacker2020
Posts: 42
Joined: Mon Jan 06, 2020 2:40 am
Real Name: Mr Mike

How are you running QLC on the raspberry pi? If you are supplying the --web-auth command line option, that error would be expected, unless you are passing basic HTTP authentication headers in the request

Another thing to double check is that you are specifying the required path in the websocket url. It should be something like ws://proxy_host/qlcplusWS

I'm able to have a working connection with the following configured in the nginx http configuration block:

Code: Select all

map $http_upgrade $connection_upgrade {
    default upgrade;
    '' close;
}
 
upstream websocket {
    server 192.168.x.x:9999;
}
 
server {
    listen 9999;
    location / {
        proxy_pass http://websocket;
        proxy_http_version 1.1;
        proxy_set_header Upgrade $http_upgrade;
        proxy_set_header Connection $connection_upgrade;
        proxy_set_header Host $host;
    }
}
And successfully connected to it using the wscat command (available via npm install wscat) wscat --connect ws://localhost:9999/qlcplusWS
joshiwoshi2005
Posts: 6
Joined: Mon Jan 07, 2019 2:15 pm
Real Name: Joshua Sanderson

Thanks for your reply,

I have ran the given raspbery pi image, and I am not supplying the web auth command line option, so I don't think it is that. I have specified the websocket URL on the websocket connect. I'll try to add the bits you have added on that server block, see if that works.

I haven't heard of wscat before so I will try that too!

I have got working a webpage that connects to the websocket, but I just haven't managed with python or node.

I'll try some of those suggestions and see..

Thanks
Post Reply