0
votes

I have an EC2 instance running a windows server. On the windows server, I installed IIS. This handles serving up http requests.

I used https://github.com/win-acme/win-acme to generate the certificate. Then I added it using the default site using the IIS manager.

Then I set up a reverse proxy following https://tecadmin.net/set-up-reverse-proxy-using-iis/

Once all this has been setup I finally boot up my node.js server on port:4000. This port is being proxied to:80.

I make an HTTP request to the server and run into two major problems I am not understanding.

One is the Websockets setup in my node.js server using https://socket.io/ are showing failed: Error during WebSocket handshake: Unexpected response code: 500

The second major issue is my request does some processing and takes a min or two to complete. Midway through it just fails. I am not sure why this is.

Before setting up HTTPS it was working via localhost on my MAC. HTTPS doesn't allow requests to be made via HTTP. So this is why I had to set up HTTPS on my windows server. Ever since I setup HTTPS I have been running into this issue. So I am pretty sure it has to do with my setup described above.

Any insights would be amazing!

1
I tried running it locally on the windows machine and it worked fine. It's just a problem when serving on HTTPS - Michael Joseph Aubry
The socket connection is working. No data is being sent to the client though - Michael Joseph Aubry
could you please share your web.config file? what is your application target framework? - Jalpa Panchal

1 Answers

0
votes

Please, make sure that you have URL Rewrite and ARR (Application Request Routing Cache) modules installed and enabled on your IIS.

For this example, let's say that your main website works under example.com domain (https and http - I usually use Letsencrypt for HTTPS certificate). I assume node with socket.io is on the same server (therefore I use 127.0.0.1 address below) and on port 4000.

You don't need to install SSL certificate on node, since IIS will encrypt communication for you.

Now it's time to configure URL Rewrite module (for the whole IIS Server, not your site).

If you want to make websockets works on http(ws) and https(wss) as well, you need to create a rewritemap. I usually create it as 'MapProtocol'.

You need 4 records there:

http -> http
https -> http
ws -> ws
wss -> ws

Then create URL Inbound Rewrite rule

Pattern:

^socket\.io/([\s\S]*)

Conditions: {HTTP_HOST} matches the pattern example.com {CACHE_URL} matches the pattern ^(.+)://

Server variables:

HTTP_Sec_WebSocket_Extensions -> none
Check 'replace the current value'

Action: rewrite

{MapProtocol:{C:1}}://127.0.0.1:4000/{R:0}
Check 'append the query string' and 'stop processing of subsequent rules'

That's all. You can now check if the rule is working by visiting: http://example.com/socket.io/socket.io.js

or

https://example.com/socket.io/socket.io.js if you have ssl certificate properly configured on your site.