首先在阿里云中配置好云盾证书
privatekey.pem是私有钥匙
certificate.pem是公有钥匙
var fs=requires('fs');
var https=requires('https');
var app=express();
var privatekey = fs.readFileSync('privatekey.pem', 'utf8');
var certificate = fs.readFileSync('certificate.pem', 'utf8');
var options={key:privatekey, cert:certificate};
var server = https.createServer(options, app);
server.listen(443);
测试
app.get("/", function (req, res){
if (req.protocol == 'https'){
res.send('https');
}
});
网友评论