美文网首页
express 配置https

express 配置https

作者: changlinwang | 来源:发表于2017-06-30 14:11 被阅读59次

    首先在阿里云中配置好云盾证书
    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');  
          }  
    });
    

    https://segmentfault.com/a/1190000008398220

    相关文章

      网友评论

          本文标题:express 配置https

          本文链接:https://www.haomeiwen.com/subject/dxabcxtx.html