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
  }
};
相关推荐
zxanz113 分钟前
HTTPS 普及之后,SSL 证书的安全边界正在悄悄收缩
安全·https·ssl
Lsetea35 分钟前
OpenSSL的showcerts没有根证书正常吗:服务端发链与show_chain构链排查
https·ssl证书·openssl·tls·证书链
lhh_qrsly4 小时前
HTTP / HTTPS / MQTT / MQTTs(嵌入式学习版)
学习·http·https
Moyu_Friday1 天前
网络安全基础-计算机网络应用与协议
网络协议·计算机网络
Lsetea1 天前
curl访问HTTPS报28 Operation timed out:连接超时与总超时分层排查
运维·https·ssl证书·curl·tls
徐同保1 天前
免费ssl证书全流程AI配置(含七牛云cdn)
网络·网络协议·ssl
Lsetea1 天前
SSL证书指纹相同但文件哈希不同:PEM、DER与公钥摘要怎么比
运维·https·ssl证书·openssl·证书链
幻智星科技2 天前
一个开源的纯FPGA网口采集卡
网络协议·fpga开发·udp
anew___2 天前
《从零手写操作系统 (48):网络协议栈基础——Socket API与TCP/IP分层架构》
网络协议·tcp/ip·架构