适用场景
用户终端在局域网内,需要跟外网的 IM 服务器完成信令和富媒体文件收发。
工作原理
在局域网内的用户终端与 IM 服务器之间搭建代理服务器,用户终端向代理服务器发送一个请求并指定目标,代理服务器向 IM 服务器转发请求并将响应返回给用户终端。
内网终端通过 ws/http 访问代理服务器,代理服务器通过 wss/https 访问 IM 富媒体服务器完成公网访问。 这种方式,满足内网以及外网用户同时访问。
Nginx 正向代理配置指引
#daemon off; # Don't run nginx in the background, good for monitoring appsworker_processes 7;worker_rlimit_nofile 200000;user root root;events {worker_connections 80000;}http {log_format access '$remote_addr:$remote_port - $server_addr:$server_port - $upstream_addr - $host[$time_local] ''"$request" $content_length $status $body_bytes_sent ''$request_time $upstream_response_time $realip_remote_addr';access_log logs/access.log access;error_log logs/error.log;resolver 119.29.29.29 ipv6=off;proxy_ssl_server_name on;server {listen 8805;location /binfo {proxy_set_header Upgrade $http_upgrade;proxy_set_header Connection "Upgrade";proxy_set_header Host "wss.im.qcloud.com";proxy_http_version 1.1;proxy_pass https://wss.im.qcloud.com/binfo$is_args$args;}location /v4/imopenstat {proxy_set_header Connection "close";proxy_set_header Host "events.im.qcloud.com";proxy_http_version 1.1;proxy_pass https://events.im.qcloud.com$uri$is_args$args;}location /upload {if ($request_method = 'OPTIONS') {add_header Access-Control-Allow-Origin *;add_header Access-Control-Allow-Headers X-Requested-With,Content-Type,X-Real-Host;add_header Access-Control-Allow-Methods 'GET,PUT,HEAD,OPTIONS';return 204;}proxy_set_header Connection "close";proxy_set_header Host "cn.imrich.qcloud.com";proxy_http_version 1.1;proxy_pass https://cn.imrich.qcloud.com$uri$is_args$args;}location /imageinfo {if ($request_method = 'OPTIONS') {add_header Access-Control-Allow-Origin *;add_header Access-Control-Allow-Headers X-Requested-With,Content-Type,X-Real-Host;add_header Access-Control-Allow-Methods 'GET,PUT,HEAD,OPTIONS';return 204;}proxy_set_header Connection "close";proxy_set_header Host "cn.imrich.qcloud.com";proxy_http_version 1.1;proxy_pass https://cn.imrich.qcloud.com$uri$is_args$args;}location /download {if ($request_method = 'OPTIONS') {add_header Access-Control-Allow-Origin *;add_header Access-Control-Allow-Headers X-Requested-With,Content-Type,X-Real-Host;add_header Access-Control-Allow-Methods 'GET,PUT,HEAD,OPTIONS';return 204;}proxy_set_header Connection "close";proxy_set_header Host "cn.imrich.qcloud.com";proxy_http_version 1.1;proxy_pass https://cn.imrich.qcloud.com$uri$is_args$args;}}}
WebSDK 配置
1. 搭建 nginx 的正向代理,如果分配的代理内网IP为10.0.0.10,则按上述指引 nginx 代理配置,IM 服务代理为10.0.0.10:8805。
2. SDK 需要升级到 v3,可参见 V3集成指引 进行升级。开发者在初始化 SDK 时,填入以下参数,即可在内网通过代理正常使用腾讯云 IM 服务。
IM 服务域名及端口
1. 中国站
1、IM 长连接服务,端口 TCP:443wss.im.qcloud.comwss.my-imcloud.comevents.im.qcloud.comevents.my-imcloud.com对应 IP 列表拉取接口:https://cloud.tencent.com/document/product/269/45438,接口参数nettype=32、IM富媒体服务,端口 TCP:443cn.imrich.qcloud.comcn.rich.my-imcloud.comfile.im.qcloud.comdown.im.qcloud.comcos.ap-shanghai.myqcloud.comcos.ap-guangzhou.myqcloud.com
2. 新加坡站
1、IM 长连接服务,端口TCP:443wsssgp.im.qcloud.comwsssgp.my-imcloud.comapisgp.im.qcloud.comapisgp.my-imcloud.comwebimsgp.im.qcloud.comwebimsgp.my-imcloud.com对应 IP 列表拉取接口:https://www.tencentcloud.com/zh/document/product/1047/367422、IM富媒体服务,端口TCP:443sgp.imrich.qcloud.comsgp.rich.my-imcloud.comcos.ap-singapore.myqcloud.comcos.ap-singapore.tencentcos.cnfilesgp.im.qcloud.comdownsgp.im.qcloud.com
3. 韩国站
1、IM 长连接服务,端口TCP:443wsskr.im.qcloud.comwsskr.my-imcloud.comapikr.im.qcloud.comapikr.my-imcloud.comwebimkr.im.qcloud.comwebimkr.my-imcloud.com对应 IP 列表拉取接口:https://www.tencentcloud.com/zh/document/product/1047/367422、IM 富媒体服务,端口 TCP:443kr.imrich.qcloud.comkr.rich.my-imcloud.comcos.ap-seoul.myqcloud.comcos.ap-seoul.tencentcos.cnfilekr.im.qcloud.comdownkr.im.qcloud.com
4. 德国站
1、IM 长连接服务,端口 TCP:443wssger.im.qcloud.comwssger.my-imcloud.comapiger.im.qcloud.comapiger.my-imcloud.comwebimger.im.qcloud.comwebimger.my-imcloud.com对应 IP 列表拉取接口:https://www.tencentcloud.com/zh/document/product/1047/367422、IM 富媒体服务,端口 TCP:443ger.imrich.qcloud.comger.rich.my-imcloud.comcos.eu-frankfurt.myqcloud.comcos.eu-frankfurt.tencentcos.cnfileger.im.qcloud.comdownger.im.qcloud.com
5. 美国站
1、IM 长连接服务,端口 TCP:443wssusa.im.qcloud.comwssusa.my-imcloud.comapiusa.im.qcloud.comapiusa.my-imcloud.comwebimusa.im.qcloud.comwebimusa.my-imcloud.com对应 IP 列表拉取接口:https://www.tencentcloud.com/zh/document/product/1047/367422、IM富媒体服务,端口TCP:443usa.imrich.qcloud.comusa.rich.my-imcloud.comcos.na-siliconvalley.myqcloud.comcos.na-siliconvalley.tencentcos.cnfileusa.im.qcloud.comdownusa.im.qcloud.com