简体   繁体   中英

Can i use ssl certificate generated locally in node server in deployment on heroku

I have created a Node js backend for my React application which is using https protocol. For this:- I created SSL using these commands:-

openssl genrsa 1024 > private.key
openssl req -new -key private.key -out cert.csr
openssl x509 -req -in cert.csr -signkey private.key -out certificate.pem

And then i use that certificate to create Secure Server https:-

  var port = normalizePort(process.env.PORT || '3000');
  app.set('port', port);

  /**
   * Create HTTP server.
   */

   var server = http.createServer(app);

   /**
   * Listen on provided port, on all network interfaces.
   */

   server.listen(port);
   server.on('error', onError);
   server.on('listening', onListening);

   app.set('secPort',port+443);
    

    
    /**
     * Create HTTPS server.
     */ 
     
    var options = {
      key: fs.readFileSync(__dirname+'/private.key'),
      cert: fs.readFileSync(__dirname+'/certificate.pem')
    };
    
    var secureServer = https.createServer(options,app);
    
    /**
     * Listen on provided port, on all network interfaces.
     */
    
    secureServer.listen(app.get('secPort'), () => {
       console.log('Server listening on port ',app.get('secPort'));
    });
    secureServer.on('error', onError);
    secureServer.on('listening', onListening);

My Question is will I get ssl error when i deploy it on heroku? If yes, then what should i do to make it deployable with secure server?

You can include self signed certificate but users will see a warning message when coming to your site. Heroku mentions they offer free SSL certificates but that's really not the case unless you have a Hobby ($7/mo) or Pro plan. Although you can get a free certificate, it cannot be included in a free Heroku app.

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