Quá trình cài đặt chứng chỉ SSL trên Node.js khá đơn giản. Quá trình này có thể được chia thành ba bước.
Đăng nhập vào trang quản lý chứng chỉ tại https://muassl.com, chọn Lấy SSL và tải về các chứng chỉ tương ứng.
Để tạo file https_server.js , sử dụng các thông số như bên dưới. bạn có thể sử dụng tên khác thay cho tên Server.js .
#vim https_server.js
var https = require('https'); var fs = require('fs'); var https_options = { key: fs.readFileSync("/path/to/private.key"), cert: fs.readFileSync("/path/to/your_domain_name.crt"), ca: [ fs.readFileSync('path/to/CA_root.crt'), fs.readFileSync('path/to/ca_bundle_certificate.crt') ] };
https.createServer(options, function (req, res) { res.writeHead(200); res.end("Welcome to Node.js HTTPS Servern"); }).listen(8443)
Ghi chú:
path/to/private.key – đường dẫn đầy đủ dẫn đến Khóa riêng.
path/to/your_domain_name.crt – đường dẫn đầy đủ dẫn đến file chứng chỉ SSL
path/to/CA_root.crt’ – đường dẫn đầy đủ đến file Root.
path/to/ca_bundle_certificate – đường dẫn đầy đủ đến CA Bundle
# node https_server.js
Sản phẩm của