本地https测试环境创建

有时需要交付兼容https的代码, 需要本地可以测试。有下面一些方法可以创建:

1. XAMPP

如果是静态页面,或者php后端,可以使用xampp。 xampp兼容mac, windows, linux各平台,下载安装即可。

它的https证书已经过期,但是只要选择依然信任,就可以在chrome下以https访问页面内容。

2. nodejs

下面的方法主要适合mac

流程:

https://medium.freecodecamp.org/how-to-get-https-working-on-your-local-development-environment-in-5-minutes-7af615770eec

代码库:

https://github.com/dakshshah96/local-cert-generator/issues

运行代码:

var path = require('path')
var fs = require('fs')
var express = require('express')
var https = require('https')

var certOptions = {
  key: fs.readFileSync(path.resolve('localhttps/server.key')),
  cert: fs.readFileSync(path.resolve('localhttps/server.crt'))
}

var app = express()

//访问当前目录静态文件
app.use('/', express.static('./'));

var server = https.createServer(certOptions, app).listen(443)

猜你喜欢

转载自blog.csdn.net/jdk137/article/details/88566994
今日推荐