Encountered this problem, mainly because the company has developed two small programs, the user base is not large, as we all know, the WeChat small program can only be launched on https
Nginx reverse proxy implements deployment of two small programs to the same server
Ready to work
- Install Nginx
- Install ssl certificate
Start configuring Nginx
The configuration file nginx.conf commented out http, turned on https, and set as follows
#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;
}
}
The above configuration is the effect
- https://www.xxx.com/api1 forwarded to http://127.0.0.1:8081/api1
- https://www.xxx.com/api2 forwarded to http://127.0.0.1:8082/api2
Start your applet service
My project is springboot, according to the above configuration, one port 8081, root path api1,
another port 8082, root path api2, so that the same domain name server is implemented and two 443 projects are deployed
Here I am using directory resolution routing. Of course, using nginx reverse proxy, you can also configure two domain names to resolve routing