vue使用https安全连接 - Wed, Apr 29, 2020
vue使用https安全连接
1. 证书生成
使用mkcert进行证书的生成 https://github.com/FiloSottile/mkcert
mkcert -install
# CA 证书位置: ~/.local/share/mkcert/rootCA.pem
mkcert 192.168.1.168
# Cert 和 Key的位置 ./192.168.1.168.pem ./192.168.1.168-key.pem
2. VUE配置
vue.config.js
const path = require('path')
const fs = require('fs')
function resolve(dir) {
return path.join(__dirname, dir)
}
module.exports = {
...
devServer: {
port: port,
https: {
key: fs.readFileSync(resolve('./certs/192.168.1.168-key.pem')),
cert: fs.readFileSync(resolve('./certs/192.168.1.168.pem')),
ca: fs.readFileSync(resolve('./certs/rootCA.pem'))
}
},
...
}