Author Topic: nodejs SSL  (Read 3903 times)

0 Members and 1 Guest are viewing this topic.

Offline
*
nodejs SSL
« on: July 02, 2021, 01:57:11 PM »
Hi there,

I hope someone can advise me on the nodejs SSL issue with private key and certificate file permission denied.

My current code as follow:-
Code: [Select]
const hostname = 'domain.com';
const port = 300;

const fs = require('fs');
const privateKey = fs.readFileSync("/etc/pki/tls/private/domain.com.key", 'utf8')
const certificate = fs.readFileSync("/etc/pki/tls/certs/domain.com.cert", 'utf8')
const credentials = {
    key: privateKey,
    cert: certificate
}

const httpServer = require('https').createServer( credentials, (req, res) => {
  res.statusCode = '200';
  res.setHeader('Content-Type', 'text/plain');
  res.end('Welcome port '+ port)
} );

httpServer.listen(port, hostname, () => {
  console.log('listening to : '+ port);
});

If i try to point to /etc/pki/tls folders this app will prompt permission denied error.
Currently, i manually copy these files to the app folder and i have to keep repeating this process everytime the AutoSSL expired.

Please advise how may i use this files without manually copy it into the app folder.

Thank you in advance.

Stay home and stay safe.

Offline
*
Re: nodejs SSL
« Reply #1 on: July 02, 2021, 02:25:09 PM »
Hello, this app have a domain associated?? I think if you binf a domain to the app and that domain is under an SSL it will work.

Offline
*
Re: nodejs SSL
« Reply #2 on: July 03, 2021, 07:16:56 AM »
that is why you have nginx/apache proxy setup via webservers domain conf module in admin where you can set https so you don't need to configure nodejs https.
VPS & Dedicated server provider with included FREE Managed support for CWP.
http://www.studio4host.com/

*** Don't allow that your server or website is down, choose hosting provider with included expert managed support for your CWP.