域名及 SSL 证书配置
1. 前置条件 🛠️
- IMServer 成功启动。
- Nginx 已成功安装,包括 SSL 模块。
- 申请域名(或子域名)及 SSL 证书,例如:
im.yourhost.com,用于 IMServer。 - 开放 443端口。
2. 域名配置模板 📝
🚀 提示: 确保替换成您的实际域名、SSL 证书路径和 SSL 密钥。
upstream msg_gateway{
#IM Message server address Multiple can be specified according to the deployment
server 127.0.0.1:10001;
}
upstream im_api{
#IM Group user api server address Multiple can be specified according to the deployment
server 127.0.0.1:10002;
}
upstream minio_s3_2{
#Minio address can be assigned to multiple modules dependingon deployment
server 127.0.0.1:10005;
}
server {
listen 443; #Listening on port 443
server_name im.yourhost.com; #Your domain
ssl on;
#Path of pem file for ssl certificate
ssl_certificate /usr/local/nginx/conf/ssh/im.yourhost.com_bundle.pem;
#Key file path of ssl certificate
ssl_certificate_key /usr/local/nginx/conf/ssh/im.yourhost.com.key;
gzip on;
gzip_min_length 1k;
gzip_buffers 4 16k;
gzip_comp_level 2;
gzip_types text/plain application/javascript application/x-javascript text/css application/xml text/javascript application/x-httpd-php image/jpeg image/gif image/png application/wasm;
gzip_vary off;
gzip_disable "MSIE [1-6]\.";
default_type application/wasm;
location /msg_gateway{
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_pass http://msg_gateway/;
}
location ^~/api/{
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection "Upgrade";
proxy_set_header X-real-ip $remote_addr;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Request-Api $scheme://$host/api;
proxy_pass http://im_api/;
}
location ^~/im-minio-api/ {
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_connect_timeout 300;
proxy_http_version 1.1;
proxy_set_header Connection "";
chunked_transfer_encoding off;
proxy_pass http://minio_s3_2/;
}
}
3. Minio 配置 🗄️
- 源码部署: 修改
config/minio.yml文件中的externalAddress值为"https://im.yourhost.com/im-minio-api". - Docker部署: 修改
.env文件中的MINIO_EXTERNAL_ADDRESS值为"https://im.yourhost.com/im-minio-api".
4. 启动 Nginx 🚀
执行命令 nginx -s reload 以重载 Nginx 配置。
5. 修改客户端 SDK 初始化参数
在客户端 SDK 中,配置初始化参数如下:
apiAddr:https://im.yourhost.com/apiwsAddr:wss://im.yourhost.com/msg_gateway