Node Express Application redirect port 443 requests to port 3000 on hostmonster

2.4k views Asked by At

I have a secure (https) node express application that I have listening on port 3000 => https://mywebsite.net:3000 running on hostmonster.

I want requests to port 443 (i.e. https://mywebsite.net / https://mywebsite.net:443) to be forwarded to my node express server application listening on port 3000 => https://mywebsite.net:3000

This is due to not be able to directly listen on port 443.

I logged into hostmonster as root.

I added the following rule to the iptable:

iptables -t nat -A PREROUTING -s 123.123.123.123 -p tcp --dport 443 -j DNAT --to-destination 
service iptables save

I see the following when I type: iptables -t nat -L

Chain PREROUTING (policy ACCEPT)
target     prot opt source               destination
DNAT       tcp  --  server.mywebsite  anywhere tcp dpt:https to: 123.123.123.123:3000
DNAT       tcp  --  server.mywebsite  anywhere tcp dpt:https to: 123.123.123.123:3000

The issue is if I type https://mywebsite.net or https://mywebsite.net:443 (same thing) in a browser it does not go to my main node express application page listening on port 3000. 

I also used Google's postman to do a request of https://mywebsite.net:443 and it does not return information from my main node express application page listening on port 3000.

So it does not appear the redirect from port 443 to port 3000 is working?

What am I missing?

1

There are 1 answers

3
duncanhall On

I'm not sure the rule you have added is correct.

The Jenkins example on forwarding with iptables suggests you should try the following:

iptables -A PREROUTING -t nat -i eth0 -p tcp --dport 443 -j REDIRECT --to-port 3000