美文网首页
http-serve 开启https服务

http-serve 开启https服务

作者: wxw_威 | 来源:发表于2022-03-19 19:43 被阅读0次

mac上 http-serve 开启一个https服务

Http-server是一个轻量级的基于nodejs的http服务器。

参照官网http-serve安装插件

1、简单起一个http服务,通过命令行

http-serve -p 8080

2、起一个https服务

先创建一个cer.pem 证书,证书名和还有其他信息可以随便填写

// 进入dist目录,执行一下命令,创建cer.pem 证书
cd ./dist  
openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem

eg:
wxw@wxwdeMacBook-Pro dist % openssl req -newkey rsa:2048 -new -nodes -x509 -days 3650 -keyout key.pem -out cert.pem
Generating a 2048 bit RSA private key
.........................................................................................+++
....................................................................+++
writing new private key to 'key.pem'
-----
You are about to be asked to enter information that will be incorporated
into your certificate request.
What you are about to enter is what is called a Distinguished Name or a DN.
There are quite a few fields but you can leave some blank
For some fields there will be a default value,
If you enter '.', the field will be left blank.
-----
Country Name (2 letter code) []:zh
State or Province Name (full name) []:zh
Locality Name (eg, city) []:zh
Organization Name (eg, company) []:zh
Organizational Unit Name (eg, section) []:zh
Common Name (eg, fully qualified host name) []:zh
Email Address []:123123123@qq.com

执行http-server -S -C cert.pem -o


http-server -S -C cert.pem -o


eg:
wxw@wxwdeMacBook-Pro dist % http-server -S -C cert.pem -o
Starting up http-server, serving ./ through https
Available on:
  https://127.0.0.1:8088
  https://192.168.3.104:8088
  https://10.129.192.68:8088
Hit CTRL-C to stop the server
open: https://127.0.0.1:8088

注意:复制生成的链接在浏览器中打开,如果打不开,显示证书不对的话,在当前目录中将cert.pem 添加到钥匙串中,并选择始终信任。

WechatIMG115.jpeg

以上就是所有过程了

相关文章

网友评论

      本文标题:http-serve 开启https服务

      本文链接:https://www.haomeiwen.com/subject/azrndrtx.html