微信公众号开发

如何在一个https服务器部署多个小程序后台代码

本文主要是介绍如何在一个https服务器部署多个小程序后台代码,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

利用nginx的localtion属性 来匹配不同的请求,分发到不同的后台地址。

 server {
       listen       443 ssl http2 default_server;
       listen       [::]:443 ssl http2 default_server;
       #  你的服务器域名
       server_name  www.xxxxxxxx.com;
       root         /usr/share/nginx/html;

       ssl_certificate "/etc/pki/Nginx/1_xxxxxxxxxx.com_bundle.crt";
       ssl_certificate_key "/etc/pki/Nginx/2_xxxxxxxxxx.com.key";
       ssl_session_cache shared:SSL:1m;
       ssl_session_timeout  10m;
       ssl_ciphers HIGH:!aNULL:!MD5;
       ssl_prefer_server_ciphers on;

       # Load configuration files for the default server block.
       include /etc/nginx/default.d/*.conf;

       location /api1 {
             proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host  $http_host;
            proxy_set_header X-Nginx-Proxy true;
            proxy_set_header Connection "";
            proxy_pass http://127.0.0.1:3030/api1; 
            proxy_redirect default;
       }
       location /api2 {
             proxy_set_header X-Real-IP $remote_addr;
            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
            proxy_set_header Host  $http_host;
            proxy_set_header X-Nginx-Proxy true;
            proxy_set_header Connection "";
            proxy_pass http://127.0.0.1:3000/api2; 
            proxy_redirect default;
       }
       error_page 404 /404.html;
           location = /40x.html {
       }

       error_page 500 502 503 504 /50x.html;
           location = /50x.html {
       }
   }
这篇关于如何在一个https服务器部署多个小程序后台代码的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!