Hello! tell me how to specify a rule for iptables redirect all https requests to nodejs ?

for http done like this

iptables

 sudo iptables -t nat -A OUTPUT -p tcp --dport 80 -j DNAT --to 127.0.0.1:3000 

nodejs

 app.route('/*').get(function(req, res) { logreq(req); //res.send(""); }); function logreq(req){ var method = req.method , len = 10 - +method.length , met = new Array(len).join(" "); console.log("\n \033[32m ",me+met,"\033[42m\033[0m", "\033[33m hostname: \033[42m\033[0m",req.headers.host, "\033[32m Pathname: \033[42m\033[0m",req.url) }; var server = app.listen(3000, '127.0.0.1', function(){ }); 
  • and your server, implemented using node.js, is ready to accept connections using the https protocol? - aleksandr barakin
  • not yet, if you implement in iptables --dport 80 change to --dport 443? - kit-kat
  • yes, if the server will accept https on the same port number 3000. - aleksandr barakin
  • one
    It is not recommended to use node.js directly, there should always be a layer in the form of a proxy server, at least because node.js is very bad when processing requests to static files. Add a layer in the form of nginx or apache. The proxy server will handle the https / ssl connection, provide the certificate and data received from the node.js client. - dr.dimitru

1 answer 1

The problem is that the nodejs will not listen to the port via ssl, and the connection will involve the use of ssl encryption. And the browser will give an ssl error, because it will wait for the ssl-handshake, but it will not receive it. E

If you need to listen to https, read the example in the documentation: https://nodejs.org/api/https.html