遇到这个问题,主要因为公司开发了两个小程序,用户体量都不大,众所周知,微信小程序上线只能https
Nginx反向代理实现两个小程序部署到同一台服务器
准备工作
- 安装Nginx
- 安装ssl证书
开始配置Nginx
配置文件nginx.conf 注释掉http,开启https,如下设置
#HTTPS server
server {
listen 443 ssl;
server_name www.xxx.com;
ssl_certificate 你的证书路径/XXXXX.pem;
ssl_certificate_key 你的证书路径/XXXXX..key;
ssl_session_cache shared:SSL:1m;
ssl_session_timeout 5m;
ssl_ciphers HIGH:!aNULL:!MD5;
ssl_prefer_server_ciphers on;
location /api1 {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8081/api1;
}
location /api2 {
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_pass http://127.0.0.1:8082/api2;
}
}
上面的配置就是效果
- https://www.xxx.com/api1 转发到了 http://127.0.0.1:8081/api1
- https://www.xxx.com/api2 转发到了 http://127.0.0.1:8082/api2
启动你的小程序服务
我的项目是springboot,按照上面配置,一个端口8081,根路径api1
另一个端口8082,根路径api2,这样就实现了同一个域名服务器,部署两个443项目
我这里是用的跟目录解析路由,当然,运用nginx反向代理,也可以配置两个域名来解析路由