微信小程序接口開發中解決https外網調試問題


准備工作

1.有一台阿里雲的Linux CentOS6 服務器,安裝支持ssl模塊的Nginx

2.有自己的域名,把域名解析到指向該服務器IP,本例中將wx.wangjiang.net 解析到服務器IP

3.為二級域名wx.wangjiang.net 申請免費的CA證書,因為小程序的業務接口不支持http協議。

 

服務端安裝frps

 wget --no-check-certificate https://raw.githubusercontent.com/clangcn/onekey-install-shell/master/frps/install-frps.sh -O ./install-frps.sh
 chmod 700 ./install-frps.sh
 ./install-frps.sh install

安裝路徑:/usr/local/frps

frps命令:frps {start|stop|restart|status|config|version}

 例如:
啟動: frps start
停止: frps stop
重啟: frps restart

[common]
bind_addr = 0.0.0.0 bind_port = 5443 dashboard_port = 6443 dashboard_user = admin dashboard_pwd = 123456 vhost_http_port = 9090 vhost_https_port = 4443 log_file = ./frps.log # debug, info, warn, error log_level = info log_max_days = 3 # privilege mode is the only supported mode since v0.10.0 privilege_token = abgbced0556 # only allow frpc to bind ports you list, if you set nothing, there won't be any limit #privilege_allow_ports = 1-65535 # pool_count in each proxy will change to max_pool_count if they exceed the maximum value max_pool_count = 50 # if tcp stream multiplexing is used, default is true tcp_mux = true [http] type = http auth_token = 12345678 custom_domains = wx.wangjiang.net [https] type = https auth_token = 12345678 custom_domains = wx.wangjiang.net

 

Nginx配置以支持https協議

編輯nginx.conf

  server {
        listen       443 ssl; server_name wx.wangjiang.net; ssl on; root html; index index.html index.htm; ssl_certificate cert/214617017500276.pem; ssl_certificate_key cert/214617017500276.key; ssl_session_timeout 5m; ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4; ssl_protocols TLSv1 TLSv1.1 TLSv1.2; ssl_prefer_server_ciphers on; location / { root html; index index.html index.htm; } location ^~ /chapter { proxy_pass http://wx.wangjiang.net:9090/chapter; add_header Access-Control-Allow-Origin '*'; } }

 

自己開發機器frps客戶端安裝

在windows機器上 點擊下載 https://github.com/fatedier/frp/releases/download/v0.17.0/frp_0.17.0_windows_amd64.zip

下載完成后解壓,編輯frpc.ini

[common]
server_addr = 101.37.29.240 server_port = 5443 token = abgbced0556 auth_token = 12345678 customer_domains = wx.wangjiang.net [http] type = http local_ip = 127.0.0.1 local_port = 8080 custom_domains = wx.wangjiang.net

雙擊frpc.exe,即可

 

測試操作流程

1.在本地啟動Web程序端口為8080 比如:http://127.0.0.1:8080/chapter2/customer

2.測試是否可通過http://wx.wangjiang.net:9090/chapter2/customer 進行訪問,如果可以證明內外面是互通的。

3.測試是否可通過https://wx.wangjiang.net/chapter2/customer進行訪問,這里走nginx做代理轉發請求到http://wx.wangjiang.net:9090/chapter2/customer,即可滿足

小程序接口調試要求。

 

參考

https://blog.csdn.net/qqr99000/article/details/79329415

https://blog.csdn.net/u011054333/article/details/71507074

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM