跳到主要内容

Nginx域名配置

1. 前置条件 🛠️

  • open-im-serverchat 成功启动。
  • Nginx 已成功安装,包括 SSL 模块。
  • 成功申请两个域名及其 SSL 证书,例如:web.xx.xx (用于 IM 服务端及 Web 端), admin.xx.xx(用于管理后台)。
  • 开放 443 和 80 端口。

2. 域名配置模板 📝

🚀 提示: 确保替换成您的实际域名、SSL 证书路径和 SSL 密钥。


#open-im-server chat Corresponding deployment address and port
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 im_chat_api{
#IM Business version login registration server address Multiple can be specified according to the deployment
server 127.0.0.1:10008;
}
upstream im_admin_api{
#IM The admin address of the commercial version can specify multiple units according to the deployment situation
server 127.0.0.1:10009;
}
upstream minio_s3_2{
#Minio address can be assigned to multiple modules dependingon deployment
server 127.0.0.1:10005;
}
upstream pc_web{
#PC web address can be validate
server 127.0.0.1:11001;
}
upstream openim_admin{
#Admin backend address can be used for validation
server 127.0.0.1:11002;
}


# Take the domain name "web.xx.xx" for example
server {
listen 443; #Listening on port 443
server_name web.xx.xx; #Your domain name
ssl on;
#Path of pem file for ssl certificate
ssl_certificate /usr/local/nginx/conf/ssh/web.xx.xx_bundle.pem;
#Key file path of ssl certificate
ssl_certificate_key /usr/local/nginx/conf/ssh/web.xx.xx.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 / {
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://pc_web/;
}

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 ^~/chat/{
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://im_chat_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/;
}
}

#Take the domain name "admin.xx.xx" for example
server {
listen 443; #listening port
server_name admin.xx.xx; #Your domain server_name
ssl on;
#Path of pem file for ssl certificate
ssl_certificate /usr/local/nginx/conf/ssh/admin.xx.xx_bundle.pem;
#Key file path of ssl certificate
ssl_certificate_key /usr/local/nginx/conf/ssh/admin.xx.xx.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 / {
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://openim_admin/;

}

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 ^~/chat/{
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://im_chat_api/;
}

location ^~/complete_admin/{
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://im_admin_api/;
}
}

#Redirection from HTTP to HTTPS redirection
server {
listen 80;
server_name web.xx.xx;
rewrite ^(.*)$ https://$host$1 permanent;
}

3. Minio 配置 🗄️

  • 源码部署: 修改 config/minio.yml 文件中的 externalAddress"https://web.xx.xx/im-minio-api".
  • Docker 部署: 修改 .env 文件中的 MINIO_EXTERNAL_ADDRESS"https://web.xx.xx/im-minio-api".

4. 启动 Nginx 🚀

执行命令 nginx -s reload 以重载 Nginx 配置,启用新的域名设置。

5. 登录验证 🔍

  • 访问IM web端:web.xx.xx
  • 访问管理后台:admin.xx.xx