md
This commit is contained in:
@@ -7,7 +7,7 @@
|
||||
# 2. 配置 GOPROXY(自动测速选最快节点)
|
||||
# 3. 安装 Node.js / npm(前端依赖)
|
||||
# 4. 安装 Docker(基础设施容器)
|
||||
# 5. 安装 Nginx 并写入 PC/OpenIM 反代(:80 API 网关,:443 PC/API/WS + COOP/COEP)
|
||||
# 5. 安装 Nginx 并写入 PC/OpenIM 反代(域名 HTTP :80)
|
||||
# 6. 写入 /etc/profile.d/deploy-env.sh(永久生效)
|
||||
#
|
||||
# 用法:
|
||||
@@ -244,7 +244,7 @@ _install_docker() {
|
||||
}
|
||||
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
# 5. Nginx — PC / OpenIM 统一入口(HTTP :80 / HTTPS :443)
|
||||
# 5. Nginx — PC / OpenIM 统一入口(HTTP :80)
|
||||
# ──────────────────────────────────────────────────────────────────────────────
|
||||
_install_pc_nginx_proxy() {
|
||||
step "安装 Nginx 并配置 OpenIM/PC 反代"
|
||||
@@ -258,15 +258,12 @@ _install_pc_nginx_proxy() {
|
||||
script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
local conf_src="${script_dir}/nginx/openim-pc-proxy.conf"
|
||||
local conf_name="openim-pc-proxy.conf"
|
||||
local deploy_ip="${DEPLOY_TEST_IP:-54.116.29.247}"
|
||||
local ssl_dir="/etc/nginx/ssl"
|
||||
local ssl_key="${ssl_dir}/openim-pc-proxy-selfsigned.key"
|
||||
local ssl_crt="${ssl_dir}/openim-pc-proxy-selfsigned.crt"
|
||||
local proxy_domain="${PC_PROXY_DOMAIN:-cms-jack.imharry.work}"
|
||||
|
||||
if [[ -f "$ENV_FILE" ]]; then
|
||||
# shellcheck source=/dev/null
|
||||
source "$ENV_FILE"
|
||||
deploy_ip="${DEPLOY_TEST_IP:-$deploy_ip}"
|
||||
proxy_domain="${PC_PROXY_DOMAIN:-$proxy_domain}"
|
||||
fi
|
||||
|
||||
if [[ ! -f "$conf_src" ]]; then
|
||||
@@ -277,47 +274,17 @@ _install_pc_nginx_proxy() {
|
||||
if ! _has nginx; then
|
||||
if _has apt-get; then
|
||||
apt-get update -y
|
||||
apt-get install -y nginx openssl
|
||||
apt-get install -y nginx
|
||||
elif _has dnf; then
|
||||
dnf install -y nginx openssl
|
||||
dnf install -y nginx
|
||||
elif _has yum; then
|
||||
yum install -y nginx openssl
|
||||
yum install -y nginx
|
||||
else
|
||||
error " 未检测到 apt/dnf/yum,请先手动安装 nginx"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
if ! _has openssl; then
|
||||
if _has apt-get; then
|
||||
apt-get update -y
|
||||
apt-get install -y openssl
|
||||
elif _has dnf; then
|
||||
dnf install -y openssl
|
||||
elif _has yum; then
|
||||
yum install -y openssl
|
||||
else
|
||||
error " 未安装 openssl,无法生成 HTTPS 自签名证书"
|
||||
return 1
|
||||
fi
|
||||
fi
|
||||
|
||||
mkdir -p "$ssl_dir"
|
||||
if [[ ! -s "$ssl_key" ]] || [[ ! -s "$ssl_crt" ]]; then
|
||||
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \
|
||||
-keyout "$ssl_key" \
|
||||
-out "$ssl_crt" \
|
||||
-subj "/CN=${deploy_ip}" \
|
||||
-addext "subjectAltName=IP:${deploy_ip},DNS:localhost" >/dev/null 2>&1 || \
|
||||
openssl req -x509 -nodes -days 3650 -newkey rsa:2048 \
|
||||
-keyout "$ssl_key" \
|
||||
-out "$ssl_crt" \
|
||||
-subj "/CN=${deploy_ip}" >/dev/null 2>&1
|
||||
chmod 0600 "$ssl_key"
|
||||
chmod 0644 "$ssl_crt"
|
||||
success " 已生成 HTTPS 自签名证书: $ssl_crt"
|
||||
fi
|
||||
|
||||
if [[ -d /etc/nginx/sites-available ]]; then
|
||||
install -m 0644 "$conf_src" "/etc/nginx/sites-available/${conf_name}"
|
||||
mkdir -p /etc/nginx/sites-enabled
|
||||
@@ -343,10 +310,10 @@ _install_pc_nginx_proxy() {
|
||||
systemctl restart nginx
|
||||
|
||||
success " Nginx 反代已启用(配置: $conf_src)"
|
||||
info " 请放行 TCP 80/443;curl -k -sS https://127.0.0.1/nginx-health 应返回 ok"
|
||||
info " 纯 IP 访问 :80 为 API 网关;HTTPS :443 会代理 PC dev server + API + WebSocket,并启用 COOP/COEP"
|
||||
info " 为避免 OpenIM WASM DB worker 在 http://公网IP:5173 下超时,建议 .env.deploy-test 设置 PC_BACKEND_ORIGIN=https://${deploy_ip}"
|
||||
info " 浏览器打开 https://${deploy_ip}/(首次访问需接受自签名证书)"
|
||||
info " 请放行 TCP 80;curl -sS -H 'Host: ${proxy_domain}' http://127.0.0.1/nginx-health 应返回 ok"
|
||||
info " HTTP :80 会代理 PC dev server + API + WebSocket"
|
||||
info " 建议 .env.deploy-test 设置 PC_BACKEND_ORIGIN=http://${proxy_domain}"
|
||||
info " 浏览器打开 http://${proxy_domain}/"
|
||||
}
|
||||
|
||||
# all 时非 root 则跳过(不中断 Go/Node/Docker)
|
||||
|
||||
17
README.md
17
README.md
@@ -283,24 +283,25 @@ TENCENT_SDK_SECRET_KEY=xxx
|
||||
> - `ws` → meetingmsg 弹幕 WebSocket `:8000`
|
||||
> - `liveApi` → livestream 直播间 API `:8888`
|
||||
|
||||
### Nginx 反代(仅公网 IP,供 PC / 浏览器访问后端)
|
||||
### Nginx 反代(域名 HTTP 入口,供 PC / 浏览器访问后端)
|
||||
|
||||
无域名时,在**测试服务器**上部署 Nginx。HTTP `:80` 继续作为 API 网关;HTTPS `:443` 额外反代 PC Vite dev server,并启用 COOP/COEP,避免 OpenIM Web 版 WASM DB worker 在 `http://公网IP:5173` 下卡在 `initDB`:
|
||||
在**测试服务器**上部署 Nginx,通过域名 `cms-jack.imharry.work` 的 HTTP `:80` 统一反代 PC Vite dev server、OpenIM API、chat-api 与 MsgGateway WebSocket;不启用 HTTPS。
|
||||
|
||||
| 路径前缀 | 后端 |
|
||||
|----------|------|
|
||||
| `/api/im/` | `127.0.0.1:10002` |
|
||||
| `/api/user/`、`/api/chat/` | `127.0.0.1:10008` |
|
||||
| `/msg_gateway` | `127.0.0.1:10001`(WebSocket) |
|
||||
| `/`(HTTPS) | `127.0.0.1:5173`(PC Vite dev server) |
|
||||
| `/` | `127.0.0.1:5173`(PC Vite dev server) |
|
||||
|
||||
1. 服务器上已执行 `05-start.sh` 等,保证 `10001/10002/10008` 在监听。
|
||||
2. 仓库根目录执行:`sudo ./deploy-test/00-init-tools.sh nginx`(会安装 `nginx` / `openssl`、生成自签名证书,并写入配置 `deploy-test/nginx/openim-pc-proxy.conf`;亦已包含在 `00-init-tools.sh` 无参的 **all** 流程末尾,需 root)。
|
||||
3. 云安全组放行 **TCP 80/443**。
|
||||
4. `.env.deploy-test` 中设置 **`PC_BACKEND_ORIGIN=https://<DEPLOY_TEST_IP>`**(无末尾 `/`),与 `DEPLOY_TEST_IP` 一致;再 `./deploy-test/07-start-frontend.sh pc` 启动 PC 时即注入 `VITE_*`。
|
||||
5. 浏览器打开 **`https://<DEPLOY_TEST_IP>/`**(首次访问需接受自签名证书),不要用 `http://<DEPLOY_TEST_IP>:5173/` 排查 OpenIM Web SDK 登录。
|
||||
2. 域名 `cms-jack.imharry.work` 已解析到测试服务器公网 IP。
|
||||
3. 仓库根目录执行:`sudo ./deploy-test/00-init-tools.sh nginx`(会安装 `nginx`,并写入配置 `deploy-test/nginx/openim-pc-proxy.conf`;亦已包含在 `00-init-tools.sh` 无参的 **all** 流程末尾,需 root)。
|
||||
4. 云安全组放行 **TCP 80**。
|
||||
5. `.env.deploy-test` 中设置 **`PC_BACKEND_ORIGIN=http://cms-jack.imharry.work`**(无末尾 `/`);再 `./deploy-test/07-start-frontend.sh pc` 启动 PC 时即注入 `VITE_*`。
|
||||
6. 浏览器打开 **`http://cms-jack.imharry.work/`**。
|
||||
|
||||
**仅 IP、:80 只做 API(不出现 CMS 静态站)**:本配置中 `openim-pc-proxy` 使用 **`listen 80 default_server`**,HTTP `GET /` 返回简短说明文本(非 CMS);HTTPS `GET /` 才代理 PC Vite。`00-init-tools.sh nginx` 会禁用 `sites-enabled/default`,并尝试去掉 `sites-available/default` 里的 `default_server`。若机上还有其它站点也写了 **`default_server`**,`nginx -t` 会报错,需在该站点配置中删除 `default_server`(保留 `listen 80;` 即可,用 **域名** 访问 CMS)。**CMS 开发**请用 **`http://IP:8001`**(UMI)。
|
||||
**域名访问**:本配置中 `openim-pc-proxy` 使用 `server_name cms-jack.imharry.work`,并监听 `80`;`GET /` 直接代理 PC Vite。`00-init-tools.sh nginx` 会禁用 `sites-enabled/default`,并尝试去掉 `sites-available/default` 里的 `default_server`,避免默认站点抢占 `:80`。若机上还有其它站点也写了 `default_server`,`nginx -t` 会报错,需在该站点配置中删除 `default_server`(保留 `listen 80;` 即可)。
|
||||
|
||||
### Docker 基础设施
|
||||
|
||||
|
||||
Reference in New Issue
Block a user