简体   繁体   中英

Adding SSL Certificate to Nodejs

I am trying to add an SSL certificate to my Nodejs website.

    const fs = require('fs');
    const https = require('https');



    const options = {
        key: fs.readFileSync('./ssl/private.key', 'utf8'),
        cert: fs.readFileSync('./ssl/certificate.crt', 'utf8'),
        requestCert:true,
        rejectUnauthorized: false
     };

var server = https.createServer(options, app);

app.listen(process.env.PORT || 443, () => {
    console.log('Server is running on 3000!')
})

The app does not throw any error but if I try to connec, I still get the connection is not secure in chrome.

I changed my code to:

https.createServer({
    key: fs.readFileSync('./ssl/private.key'),
    ca:fs.readFileSync('./ssl/ca_bundle.crt'),
    cert: fs.readFileSync('./ssl/certificate.crt')
}, app).listen(443);

and it worked

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM