100字范文,内容丰富有趣,生活中的好帮手!
100字范文 > Nginx 反向代理 配置 微信小程序WSS 环境

Nginx 反向代理 配置 微信小程序WSS 环境

时间:2022-04-28 04:37:28

相关推荐

Nginx 反向代理 配置 微信小程序WSS 环境

1. 首先你得确认 你的域名是否已经绑定服务器

2. 下载 Nginx 并解压到 云服务器 或者 虚拟机中

nginx: download

3. 验证 Nginx是否运行正常 在云服务器上 浏览器里运行http://localhost:80/

正常情况下 你可以看到 Nginx的 欢迎界面

Nginx 启动失败 如何解决关于 Nginx 反代理 启动失败相关问题_Geek7-CSDN博客

4. 申请SSL证书 以腾讯云为例

申请SSL证书流程略过

申请证书完成后 下载证书

将证书压缩包解压后 复制里面的Nginx文件夹拖到云服务器中的 Nginx解压目录 conf 文件夹下

4.配置Nginx

修改nginx/conf/nginx.conf文件

#user nobody;worker_processes 1;events {worker_connections 1024;}http {include mime.types;default_type application/octet-stream;sendfile on;keepalive_timeout 65;server {listen 8090;server_name localhost;location / {root html;index index.html index.htm;}error_page 500 502 503 504 /50x.html;location = /50x.html {root html;}}# HTTPS server#upstream gameserver{server 127.0.0.1:9443 weight=1;}server{listen 443 ssl;server_name ; #填写绑定证书的域名ssl on;ssl_certificate .crt证书文件路径;ssl_certificate_key .key证书文件路径;ssl_session_timeout 5m;ssl_protocols TLSv1 TLSv1.1 TLSv1.2; #按照这个协议配置ssl_ciphers ECDHE-RSA-AES128-GCM-SHA256:HIGH:!aNULL:!MD5:!RC4:!DHE; #按照这个套件配置ssl_prefer_server_ciphers on;#微信小游戏location / {#limit_req zone=allips burst=5 nodelay;#limit_req zone=allips burst=1 nodelay;proxy_pass http://gameserver;proxy_set_header Host $host;proxy_set_header X-Real-IP $remote_addr ;proxy_set_header X-Forwarded-For $remote_addr;proxy_http_version 1.1;proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "Upgrade";}}}

重启动代理 在Nginx根目录下 打开命令行 输入 nginx -s reload

5.修改 客户端连接地址

不需要 修改 服务器代码

客户端这边 只需要修改成套接字的连接方式为 服务器地址 wss + 域名+ 443

6.本篇案例

本篇 客户端Socket的地址是wss://:443

本篇 服务器的Socket的端口设置为9443 一般你服务器只需要填写一个端口信息 那么在本机访问地址就是 127.0.0.1:9443

本篇用Nginx 监听wss://:443 Socket消息和 来自 :443 的http请求 将事件消息转发到本地 127.0.0.1:9443地址

服务器全程不进行任何修改操作

客户端 由之前的请求地址ws://47.102.7.111:9443 改为了wss://:443

在本次案例中 Nginx 起到了一个 转发站的作用 将 wss://:443 和 127.0.0.1:9443 之间的消息转发

websocket 在线测试工具

websocket在线测试

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。