当前位置:   article > 正文

EMQX MQTT 微信小程序接入搭建_微信小程序 emqx

微信小程序 emqx

1、通过域名去申请CA 颁发的证书:xxx.com_cert_chain.pem && xxx.com_key.key

2、域名需要在小程序管理后台(开发 -> 开发设置 -> 服务器域名 -> socket 合法域名)添加

3、证书申请绑定时,必须与所使用的服务器域名一致,建议使用 Nginx 来做反向代理并终结证书,相关配置如下:

  1. server {
  2. listen 443 ssl;
  3. server_name xxx.lz-qs.com; // 签名证书域名
  4. ssl_certificate /usr/local/nginx/cert/ssl/xxx_cert_chain.pem;
  5. ssl_certificate_key /usr/local/nginx/cert/ssl/xxx_key.key;
  6. ssl_session_timeout 5m;
  7. ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:ECDHE:ECDH:AES:HIGH:!NULL:!aNULL:!MD5:!ADH:!RC4;
  8. ssl_protocols TLSv1 TLSv1.1 TLSv1.2;
  9. ssl_prefer_server_ciphers on;
  10. # 添加反向代理
  11. location /mqtt {
  12. proxy_pass http://192.168.10.xx:8084/mqtt;
  13. proxy_set_header Host $host;
  14. proxy_set_header X-Real-IP $remote_addr;
  15. proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
  16. # client_max_body_size 35m;
  17. proxy_http_version 1.1;
  18. proxy_set_header Upgrade $http_upgrade;
  19. proxy_set_header Connection "upgrade";
  20. }
  21. }

4、安装EMQX可以参考这个链接:EQMX+Nginx集群搭建_emqx nginx_刺-客的博客-CSDN博客

5、 EMQX 配置,打开 etc/emqx.conf 配置文件,修改以下配置:

  1. ## Path to the file containing the user's private PEM-encoded key.
  2. ##
  3. ## See: listener.ssl.$name.keyfile
  4. ##
  5. ## Value: File --CA证书路径
  6. listener.wss.external.keyfile = /usr/local/nginx/cert/ssl/xxx_key.key
  7. ## Path to a file containing the user certificate.
  8. ##
  9. ## See: listener.ssl.$name.certfile
  10. ##
  11. ## Value: File--CA证书路径
  12. listener.wss.external.certfile = /usr/local/nginx/cert/ssl/xxx_cert_chain.pem
  13. ## Path to the file containing PEM-encoded CA certificates.
  14. ##
  15. ## See: listener.ssl.$name.cacert
  16. ##
  17. ## Value: File--CA证书路径
  18. listener.wss.external.cacertfile = /usr/local/nginx/cert/ssl/xxx_cert_chain.pem

 6、用客户端连接测试一下:

  

 至此已完成!

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/Gausst松鼠会/article/detail/175519
推荐阅读
相关标签
  

闽ICP备14008679号