I have a simple NodeJs Websocket application running, the code for it is
// Importing the required modules
const WebSocketServer = require('ws');
// Creating a new websocket server
const wss = new WebSocketServer.Server({ port: 8090 })
// Creating connection using websocket
wss.on("connection", ws => {
console.log("new client connected");
// sending message
ws.on("message", data => {
console.log(`Client has sent us: ${data}`)
});
// handling what to do when clients disconnects from server
ws.on("close", () => {
console.log("the client has connected");
});
// handling client connection error
ws.onerror = function () {
console.log("Some Error occurred")
}
});
console.log("The WebSocket server is running on port 8090");
I want to proxy the requests coming to port 80 and redirect it to the 8090. I am using Nginx for reverse Proxy, with configuration
server {
listen 172.30.5.139:80;
listen 172.30.5.139:443;
location / {
proxy_pass "http://127.0.0.1:8090/";
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "upgrade";
proxy_set_header Host $http_host;
}
}
While testing I can connect via
ws://1.2.3.4:443/
But cannot connect via
ws://1.2.3.4/
In Nginx access log I am seeing the following error:
51.24.28.78 - - [06/Oct/2022:14:19:42 +0000] "GET /ws HTTP/1.1" 426 16 "-" "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/105.0.0.0 " "-"
Need help in figuring out the underlying issue, as I am planning to support both ws and wss by implementing SSL on Nginx.