本地配置运行https协议
1.使用 mkcert 生成受信任的证书
brew install mkcert
或者
Mac-mini h5 % mkdir -p cert
1.2. 生成证书
openssl req -x509 -newkey rsa:4096 -keyout cert/cert.key -out cert/cert.crt -days 365 -nodes -subj "/C=CN/ST=State/L=City/O=Organization/CN=localhost"
检查当前目录和证书生成情况:
Mac-mini h5 % ls -la cert/
2.检查当前的 nuxt.config.ts 配置
server: {port: 3000,host: true, // 允许外部访问https: isDevelopment? {key: fs.readFileSync(path.resolve(__dirname, './cert/cert.key')),cert: fs.readFileSync(path.resolve(__dirname, './cert/cert.crt')),}: false,
- package.json
"dev:https": "nuxt dev --host --https",
- 运行
npm run dev:https