I have a running Node app that is live and works fine on http and https.
I setup Nginx and it is also running fine, tested with an sshtunnel, and it is getting a correct response from static files (such as MyPath/index.html).
However, I am trying to get Nginx to work as a reverse-proxy for Node. Because I want to make another app on my machine, and Nginx should sort the incoming requests for each app.
But there seems to be an issue with Nginx I cannot figure out. I suspect it is a config problem. When I try to reach my Node app through SSH tunnel on localhost, instead of getting a webpage, I am always getting an error page from my browser, saying:
This site can’t provide a secure connectionlocalhost sent an invalid response. ERR_SSL_PROTOCOL_ERROR.
When I try to reach it from WAN, it just times out.
Nginx config
server {
listen [::]:4444 default_server;
server_name localhost mysite.com www.mysite.com;
access_log /home/mysite/access-log;
location / {
proxy_pass http://127.0.0.1:5555;
}
}
I tried changing http://127.0.0.1:5555 to https://127.0.0.1:6666 but that didn't change anything.
Node app
const port = 5555;
const secureport = 6666;
...
const privateKey = fs.readFileSync('PATHTOCERT');
const certificate = fs.readFileSync('PATHTOKEY');
const credentials = {key: privateKey, cert: certificate};
... I use an express app instance here, also configured CSP with helmet. But I don't think that's the problem, because I disabled helmet and that did not solve anything. ...
const httpServer = http.createServer(app);
const httpsServer = https.createServer(credentials, app);
httpServer.listen(port);
httpsServer.listen(secureport);