前言
之前在服务器搭建的项目都是用http的,但是一般来说都要换成https;因为https比http更加安全,数据不再是明文传输,更不容易被攻击/被第三方广告光顾;所以就有了将http换成https的想法。
第一个需要升级的项目是我使用nuxt3重构的博客项目,期间遇到了诸多问题,所以想记录下踩坑过程
1. 使用PM2搭建
安装PM2
![](https://img-blog.csdnimg.cn/img_convert/28e32ee5242065580c6de0eefb6250e7.png)
通过PM2添加node项目
启动文件选择.output/server/index.mjs
![](https://img-blog.csdnimg.cn/img_convert/1beab69a7ca35e379c9d1c2eba63621a.png)
配置端口
![](https://img-blog.csdnimg.cn/img_convert/0e49d0cf7b25361c6a2ea8e95e5be252.png)
创建项目映射
![](https://img-blog.csdnimg.cn/img_convert/aebebc1a65fe24efaebc353af2495fce.png)
映射创建成功后,在宝塔的网站面板(php项目)会出现这个项目
2. 配置SSL(https)
进入php项目面板
点击宝塔菜单-网站-php项目
![](https://img-blog.csdnimg.cn/img_convert/169ae7688486826e688ed84e12e4398a.png)
点击设置
![](https://img-blog.csdnimg.cn/img_convert/43d0fcb840562b65a60bb07e7b6b4b45.png)
选择Nuxt3运行目录
选择运行目录.output/server/public
使用Nuxt3搭建的项目上线后,首页加载的内容会从public文件取,所以一定要记得改运行目录!
![](https://img-blog.csdnimg.cn/img_convert/8c20ba3b7f68cf837e4dddf5bd38d6eb.png)
点击配置文件-配置反向代理
![](https://img-blog.csdnimg.cn/img_convert/d34bdfd61695b79aae0e8121c6af56e1.png)
配置ngnix反向代理
location / {
proxy_pass http://localhost:3000;
}
此处的3000端口与PM2项目端口要相同
选择SSL进行配置
![](https://img-blog.csdnimg.cn/img_convert/b6d4dd96011103d7771bf31cb1d5d578.png)
申请SSL证书
![](https://img-blog.csdnimg.cn/img_convert/29f6b4c09903e19487b9692e6a109fa1.png)
一级域名推荐使用云服务器提供SSL证书
如果一级域名使用上述的Let's Encrypt里的证书,同时二级域名也使用同类证书,会导致一级域名证书失效。(别问我怎么知道的,因为这个捣鼓了很久)
腾讯云的可以在这个地址申请[ https://console.cloud.tencent.com/ssl/dsc/apply](https://console.cloud.tencent.com/ssl/dsc/apply)
![](https://img-blog.csdnimg.cn/img_convert/9546ee35db174720a3e72ff16d4f50a9.png)
3.https网址测试
![](https://img-blog.csdnimg.cn/img_convert/449e9c76f927dbfbdb877b7cc02d53da.png)
成功实现https项目上线,完结撒花