网友真实露脸自拍10p,成人国产精品秘?久久久按摩,国产精品久久久久久无码不卡,成人免费区一区二区三区

小程序模板網

nginx簡單配置同時支持微信小程序https/wss協議

發布時間:2018-05-08 14:19 所屬欄目:小程序開發教程

微信小程序需要使用https與wss能才進行連接,雖然開發模式下可以使用http與ws,但發布的時候還是需要安全協議,網上的各種配置是超多超復雜的,這里已經對nginx指定版本進行最簡單的配置,可用。 

 

使用教程

nginx版本

 

				
  1. $ nginx -v
  2. nginx version: nginx/1.12.2

系統Centos7

 

				
  1. $ uname -r
  2. 4.14.11-1.el7.elrepo.x86_64

cat /etc/nginx/conf.d/test.conf

 

				
  1. server {
  2. listen 80;
  3. server_name test.dounine.com;
  4. return 301 https://$host$request_uri;
  5. }
  6.  
  7. server {
  8. listen 443;
  9. server_name test.dounine.com;
  10. ssl on;
  11. ssl_certificate /etc/nginx/ssls/test.xxxx.pem;
  12. ssl_certificate_key /etc/nginx/ssls/test.xxxx.key;
  13.  
  14. location / {
  15. client_max_body_size 100m;
  16. proxy_pass http://localhost:7777;
  17. proxy_set_header Host $host;
  18. proxy_set_header X-Real-IP $remote_addr;
  19. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  20. proxy_set_header Upgrade $http_upgrade;
  21. proxy_set_header Connection "Upgrade";
  22. }
  23.  
  24. }

微信小程序代碼

 

				
  1. wx.connectSocket({
  2. url: 'wss://test.dounine.com/ws'
  3. });
  4. wx.onSocketOpen(function(res) {
  5. console.info('websocket連接成功');
  6. });
  7. wx.onSocketClose(function(res) {
  8. console.log('WebSocket 已關閉!')
  9. });
  10. wx.onSocketError(function(res){
  11. console.log('WebSocket連接打開失敗,請檢查!')
  12. });
  13. wx.onSocketMessage(function(res) {
  14. console.log('收到服務器內容:' + res.data)
  15. })


易優小程序(企業版)+靈活api+前后代碼開源 碼云倉庫:starfork
本文地址:http://www.xiuhaier.com/wxmini/doc/course/24339.html 復制鏈接 如需定制請聯系易優客服咨詢:800182392 點擊咨詢
QQ在線咨詢
AI智能客服 ×