Azure WebSockets + NodeBB + Node.js Proxy
-
I have 2 webapps running on Azure (linux servers).
One webapp is running NodeBB (v1.12.1) - https://my-forum.azurewebsites.net
This app should not be accessed directly, instead, it is proxied into the second web app running on Azure.
The NodeBB config is set up so that the 'url' is 'https://my-website.azurewebsites.net/forums/'
I have added URLs in the
socket.io:origins
nconf to be able to make WebSocket requests from other URLs. The values look like this:
http://my-website.azurewebsites.net:* https://my-website.azurewebsites.net:* https://my-forum.azurewebsites.net:* https://localhost:*
The main website (https://my-website.azurewebsites.net) is a Node.js & Express app with some frontend routes, api routes and uses the
http-proxy-middleware
module to proxy requests to the forum. The setup and configuration of that looks like this:... const proxy = require('http-proxy-middleware'); const forumProxy = proxy({ target: process.env.FORUM_URL, changeOrigin: true, ws: true, secure: true, xfwd: true, logLevel: 'debug' }); app.use('/forums', forumProxy); const mainserver = http.createServer(app); ... other config mainserver.on('upgrade', forumProxy.upgrade);
When I run the main website locally (https://localhost:3000) and Proxy the NodeBB forum, I can see that WebSockets are established correctly and messages are exchanged between the local version of the website and the Azure hosted NodeBB forum.
However, when the website is on Azure it Proxy's the URLs and the site perfectly fine but the WebSocket connection does not work. A '2probe' message is sent by the main website but a connection is never established and messages are not exchanged.
Accessing the forum URL directly works as expected, including WebSocket messages being exchanged.
Both the main website and forum have a web.config which contains:
<system.webServer> <webSocket enabled="false"/> </system.webServer>
Both apps also have the --web-sockets-enabled=true value set on the server (which was set via PowerShell).
As I understand it, this makes WebSocket enabled on the server and the value in the web.config of 'false' is to turn off iis WebSockets and let Node.js handle it.
There seems to be a problem with 2 Azure servers talking to each other via WebSockets. Local to Azure works fine.
Why is it that 'https://my-website.azurewebsites.net' cannot establish a WebSocket to 'https://my-forum.azurewebsites.net'? but Local to Azure can?
-
@julian Thanks for your reply. That hasn't worked, unfortunately
It looked like it was supposed to be a string from this post - https://community.nodebb.org/topic/13388/faq-websockets-not-working-due-to-misconfigured-originsI'm not sure if the problem is specific to Azure or it's to do with these origins. Azure (webapp) to Azure (NodeBB) doesn't like the websocket part, but polling is fine (there is a couple of failing polls every 5minutes or so, but generally works). With the websocket request the '2probe' message is sent but nothing is received.
Local (webapp) to Azure (NodeBB) is working perfectly with the WebSocket messages being sent and received.
-
It might be worth escalating this up to Azure support. I know websockets isn't new by any means anymore, but there could likely be some edge cases (such as Azure-to-Azure) where websockets is blocked unintentionally for whatever reason...?
-
@julian Hey Julian, I did actually manage to resolve this with a combination of two things:
- socket.io:origins - space separated string of domains which needs to access the forum
- socket.io:address - set this to the domain on which the forum lives (not it's frontend URL)
We have a very niche setup for our forum (Azure + Node.js Proxy) which I think gave a few red herrings along the way, however, I do think we can suggest some updates to documentation & possible feature requests of NodeBB which might help other users in the future
Thanks for your help and the other regular contributors who have answered other questions I've asked along the way