node.js - Adding a SSL certificate to an Express Site -
I have a small site on which I have been working to add an SSL certificate This code
#! / Usr / bin / env node var debug = runs in Express with the expected ('debug') ('one-end-end'), app = ('../app'), fs = require ('Fs'), http = need ('http'), https = ('https'), express = require ('express'); Var keyPath = '../ssl/key.key'; Var certPath = '../ssl/cert.crt'; Var caPath = '../ssl/cert.crt'; Var ports = 3000; If (app .get ('env') === 'output') {port = 80; } If (fs.existsSync (keypath) and fs.existsSync (certPath)) {port = 443; Var option = {key: fs.readFileSync (keyPath), cert: fs.readFileSync (certPath),}; Var server = https.createServer (option, app) .listen (port, function) {console.log ("listen on express server port" + port);)); } Else {var server = app.listen (port, function) (); Console.log ('server port was started on port); Debug ('listen to express server on port' + port);); }
I did not create the necessary files to create the files, but it was used, which calls for completeness:
& gt; ; Openssl genrsa -out ~ / domain.com.ssl / domain.com.key 2048` & gt; Openssl req -new -key ~ / domain.com.ssl / domain.com.key -out ~ / domain.com.ssl / domain.com.csr`
The only thing I received from the person who bought the certificate was a zip file containing two .rt
files. The content for one is:
----- BEGIN certificate ----- .... ----- end certificates -----
and second
----- BEGIN certificate ----- .... ----- end certificates ----- --- - BG Certificates ----- ----- End Certificate ----- ----- BEGIN Certification ----- .... ----- End Certificate - - -
I am using the key file created in the initial step in the express file, but I am not sure which file my CA is and which of my certificates I have tried some different variations, but I always get the error "This webpage is not available" in Chrome
The first file is probably your certificate, and the second file contains the CA series. Each certificate in the CA need to pass separately in each array in each array. It does not support multiple compatible certificates in a single file.
Each certificate should be put in its file (i.e. ca1.crt
, ca2.crt
, and ca3.crt
) and read separately.
https.createServer ({key: fs.readFileSync ('domain.com.key'), certificate: Fs.readFileSync ('domain.com.crt'), ca: [fs. ReadFileSync ('ca1.crt'), fs.readFileSync ('ca2.crt'), fs.readFileSync ('ca3.crt')]});
Comments
Post a Comment