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)
|
||||
|
||||
Reference in New Issue
Block a user