const https = require('https');
const http = require('http');
const fs = require('fs');
 
// 读取证书文件
const options = {
  key: fs.readFileSync('/root/project/cert/3762675_yangxiang.fun.key'),
  cert: fs.readFileSync('/root/project/cert/3762675_yangxiang.fun.pem')
};
 
// 创建https服务
const server = https.createServer(options, function(req, res) {
  res.writeHead(200, {'Content-Type': 'text/plain'});
  res.end('hello world');
});
server.listen(443);
 
// 创建http服务,重定向到https
http.createServer((req,res)=>{
  res.writeHead(301, {'Location': 'https://yangxiang.fun/'});
    res.end();
}).listen(80);

  

相关文章:

  • 2021-07-07
  • 2021-12-10
  • 2021-06-22
  • 2021-11-19
  • 2021-08-09
  • 2022-12-23
猜你喜欢
  • 2021-12-03
  • 2021-06-04
  • 2021-12-03
  • 2021-11-21
  • 2022-12-23
相关资源
相似解决方案