uniapp 配置本地 https 开发环境(基于 Vue2 的 uniapp)

1、生成本地 HTTPS 证书(mac)打开终端,运行以下命令:

javascript 复制代码
mkdir ~/ssl-cert && cd ~/ssl-cert

2、生成私钥:

javascript 复制代码
openssl genrsa -out localhost.key 2048

3、生成自签名证书(有效期365天):

javascript 复制代码
openssl req -new -x509 -key localhost.key -out localhost.crt -days 365 -subj "/CN=localhost"

项目目录里面会生成两个文件,分别是:

server.key

server.crt

4、配置 vue.config.js(用于 uniapp H5 模式)

在根目录下找到或者创建 vue.config.js,host:localhost(本地),host:'0.0.0.0'(你的 ip)添加如下:

javascript 复制代码
const fs = require('fs');
const path = require('path');

module.exports = {
  devServer: {
    https: {
      key: fs.readFileSync(path.resolve(__dirname, 'server.key')),
      cert: fs.readFileSync(path.resolve(__dirname, 'server.crt'))
    },
    host: '0.0.0.0',
    port: 8080,
    open: true
  }
};
相关推荐
LK_0720 小时前
【FastAPI】基础篇 01|开始之前:API、HTTP 与 FastAPI 到底是什么
网络协议·http·fastapi
阿星_20 小时前
pydio登陆不了分析问题
网络协议·http·https
Joy T21 小时前
Gzip 压缩原理与实践:HTTP 响应压缩、性能收益与工程配置
网络·网络协议·http
头发还在的女程序员1 天前
基于 Spring Boot + Vue 3 + uni-app 的灵活用工系统:四端架构与业务流程设计
vue.js·spring boot·uni-app·灵活用工·灵工系统
陈希1232 天前
Nginx 从入门到能扛事:反向代理、负载均衡与 HTTPS 实战
nginx·https·负载均衡
博客zhu虎康3 天前
实现局域网P2P通信:内网发送消息
网络·网络协议·p2p
Dumbness3 天前
订阅消息弹窗必须在用户点击里调:联调实验室里 timing 和 Mock 支付通知踩的坑
javascript·uni-app
FungLeo3 天前
成为全栈·基础补充·域名、DNS 与 HTTPS 证书
https·网络基础·网站部署·tls证书·成为全栈·域名 dns
xixingzhe23 天前
AI 对话打字机效果:SSE 和 HTTP 的区别与适用场景
网络·网络协议·http
叼烟扛炮4 天前
Linux 学习笔记(五十一):数据链路层与 ARP 协议——局域网寻址与黑客骗局
linux·网络·网络协议·php·tcpdump