nodejs SSL

Started by simpli, July 02, 2021, 01:57:11 PM

Previous topic - Next topic

simpli

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:-

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.

mrmorales

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.

studio4host

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.