feat(nginx): 容器直接绑定 0.0.0.0:80,宿主机无需 nginx 配置
将内置 nginx 从 127.0.0.1:11223 改为直接绑定宿主机 0.0.0.0:80。 上层 nginx 直接 proxy_pass 到本机 IP:80 即可,省去宿主机 nginx 配置环节。 同步更新端口检查(80)、部署完成提示、runbook/configuration/README 文档。 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
这个提交包含在:
父节点
f490b62f0b
当前提交
8b0c05e0e4
10
README.md
10
README.md
@ -14,9 +14,9 @@ curl -fsSL https://xuqinmin.com/xuqmGroup/XuqmGroup-PrivateDeploy/raw/branch/mai
|
||||
## 部署架构
|
||||
|
||||
```
|
||||
用户 nginx(宿主机)
|
||||
上层 nginx(任意层级)
|
||||
│
|
||||
└── 127.0.0.1:11223 内置 nginx 容器(统一入口)
|
||||
└── 本机 IP:80 内置 nginx 容器(统一入口,无需宿主机 nginx)
|
||||
│
|
||||
├── tenant-service /api/ /actuator/
|
||||
├── file-service /file/
|
||||
@ -28,7 +28,7 @@ curl -fsSL https://xuqinmin.com/xuqmGroup/XuqmGroup-PrivateDeploy/raw/branch/mai
|
||||
└── push-service (厂商回调,按需)
|
||||
```
|
||||
|
||||
内置 nginx 容器属于 `base` 必启服务,对外只暴露 `127.0.0.1:11223`。宿主机 nginx 只需一条 `proxy_pass` 指向该端口,内部路由由容器负责。各业务容器(11224–11231)仍绑定宿主机以便直接调试,正常流量全部走 11223。
|
||||
内置 nginx 容器直接绑定宿主机 `0.0.0.0:80`,**宿主机无需任何 nginx 配置**,上层 nginx 直接 proxy_pass 到本机 IP 即可。各业务容器(11224–11231)绑定 `127.0.0.1`,仅用于本地调试。
|
||||
|
||||
## 租户初始化方式
|
||||
|
||||
@ -59,8 +59,8 @@ curl -fsSL https://xuqinmin.com/xuqmGroup/XuqmGroup-PrivateDeploy/raw/branch/mai
|
||||
## 注意事项
|
||||
|
||||
- `application.yml` 中数据库 URL 硬编码了生产地址,`docker-compose.yml` 的 `environment:` 节负责覆盖,**不能删除**
|
||||
- 宿主机 nginx `proxy_pass` 写 `http://127.0.0.1:11223`,同时须透传 `Upgrade` / `Connection` 头(WebSocket 必需),详见 [docs/runbook.md](docs/runbook.md)
|
||||
- 不能写 `localhost`,部分系统 localhost 解析为 IPv6
|
||||
- 上层 nginx `proxy_pass` 写本机 IP(端口 80),须透传 `Upgrade` / `Connection` 头(WebSocket 必需),每层都要加,详见 [docs/runbook.md](docs/runbook.md)
|
||||
- 宿主机本身无需配置 nginx
|
||||
|
||||
## 文档
|
||||
|
||||
|
||||
@ -84,14 +84,14 @@ services:
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# 内置路由 nginx(必须)
|
||||
# 统一处理所有内部路由,对外只暴露 127.0.0.1:11223。
|
||||
# 宿主机 nginx 只需一条 proxy_pass http://127.0.0.1:11223 即可。
|
||||
# 统一处理所有内部路由,直接绑定宿主机 80 端口。
|
||||
# 上层 nginx 直接 proxy_pass 到本机 IP:80,宿主机无需额外 nginx 配置。
|
||||
# ---------------------------------------------------------------------------
|
||||
nginx:
|
||||
image: nginx:1.27-alpine
|
||||
profiles: ["base"]
|
||||
ports:
|
||||
- "127.0.0.1:11223:80"
|
||||
- "80:80"
|
||||
volumes:
|
||||
- ./config/nginx/nginx.conf:/etc/nginx/nginx.conf:ro
|
||||
- ./config/nginx/conf.d:/etc/nginx/conf.d:ro
|
||||
|
||||
@ -80,7 +80,7 @@ environment:
|
||||
| 11230 | license-service | 8085 | `/api/license/` |
|
||||
| 11231 | push-service | 8083 | 厂商回调(按需) |
|
||||
|
||||
所有端口绑定 `127.0.0.1`,11224–11231 仅用于直接调试。宿主机 nginx 代理到内置 nginx 端口 11223,详见 [runbook.md](runbook.md)。
|
||||
内置 nginx 绑定宿主机 `0.0.0.0:80`,上层直接 proxy_pass 到本机 IP 即可。11224–11231 绑定 `127.0.0.1`,仅用于直接调试。
|
||||
|
||||
## 容器内部通信
|
||||
|
||||
@ -99,7 +99,7 @@ SDK_TENANT_SERVICE_URL: "http://tenant-service:9001"
|
||||
|
||||
## 内置 nginx
|
||||
|
||||
nginx 容器属于 `base` 必启服务,绑定 `127.0.0.1:11223`,统一处理所有内部路由(按 Docker 服务名转发,无需关心各服务端口)。宿主机 nginx 只需一条 `proxy_pass http://127.0.0.1:11223` 加 WebSocket 透传头,配置见 [runbook.md](runbook.md#nginx-配置)。
|
||||
nginx 容器属于 `base` 必启服务,直接绑定宿主机 `0.0.0.0:80`,统一处理所有内部路由(按 Docker 服务名转发,无需关心各服务端口)。**宿主机无需额外 nginx 配置**,上层 nginx 直接 proxy_pass 指向本机 IP:80 即可,详见 [runbook.md](runbook.md#nginx-配置)。
|
||||
|
||||
## `config/vendors/`
|
||||
|
||||
|
||||
@ -20,13 +20,13 @@ curl -fsSL https://xuqinmin.com/xuqmGroup/XuqmGroup-PrivateDeploy/raw/branch/mai
|
||||
|
||||
## Nginx 配置
|
||||
|
||||
部署内置了一个 nginx 容器处理所有内部路由,对外只暴露 `127.0.0.1:11223`。
|
||||
部署内置了一个 nginx 容器处理所有内部路由,直接绑定宿主机 `0.0.0.0:80`。**宿主机无需任何 nginx 配置。**
|
||||
|
||||
宿主机 nginx 的 server 块内只需加一条:
|
||||
上层 nginx 直接 `proxy_pass` 指向本机 IP(端口 80)即可,例如:
|
||||
|
||||
```nginx
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:11223;
|
||||
proxy_pass http://192.168.x.x; # 填写部署服务器 IP
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
@ -37,7 +37,7 @@ location / {
|
||||
}
|
||||
```
|
||||
|
||||
> `proxy_http_version 1.1` 和 `Upgrade`/`Connection` 头是 WebSocket(IM)必需的,不能省略。
|
||||
> 如果有多层 nginx 代理,**每一层**都必须加上 `proxy_http_version 1.1` 和 `Upgrade`/`Connection` 头,否则 IM WebSocket 握手会在中间某层断开。
|
||||
|
||||
内置 nginx 路由配置在 `config/nginx/conf.d/xuqm.conf`,使用 Docker 服务名路由到各容器,无需关心具体端口。
|
||||
|
||||
@ -47,10 +47,10 @@ location / {
|
||||
|
||||
| 宿主机端口 | 说明 |
|
||||
|-----------|------|
|
||||
| **11223** | 内置 nginx 入口(宿主机 nginx 指向此端口) |
|
||||
| **80** | 内置 nginx 入口(上层 nginx 直接指向此端口) |
|
||||
| 11224–11231 | 各业务容器(绑定 127.0.0.1,调试用) |
|
||||
|
||||
各业务容器端口仅用于直接调试,正常流量全部走 11223。
|
||||
各业务容器端口仅用于直接调试,正常流量全部走 80。
|
||||
|
||||
---
|
||||
|
||||
|
||||
@ -220,7 +220,7 @@ DISK_FREE_GB="$(df -BG "$ROOT_DIR" | awk 'NR==2{gsub(/G/,"",$4); print $4}')"
|
||||
fail "磁盘可用空间不足(需 ≥10 GB,当前 ${DISK_FREE_GB:-?} GB)"
|
||||
ok "磁盘可用: ${DISK_FREE_GB} GB"
|
||||
|
||||
for port in 11223; do
|
||||
for port in 80; do
|
||||
if ss -tlnp 2>/dev/null | grep -q ":${port} " || \
|
||||
netstat -tlnp 2>/dev/null | grep -q ":${port} "; then
|
||||
warn "端口 ${port} 已被占用(如已是本脚本的 nginx 容器则无影响,否则会端口冲突)"
|
||||
@ -778,24 +778,9 @@ if [ "$DEPLOY_MODE" = "new" ]; then
|
||||
else
|
||||
printf ' 密码: 同生产平台密码(原样迁移,未重置)\n'
|
||||
fi
|
||||
printf '\n \033[1m宿主机 nginx 配置(server 块内加入以下内容):\033[0m\n'
|
||||
printf '\033[0;37m'
|
||||
cat <<'NGINX_REF'
|
||||
location / {
|
||||
proxy_pass http://127.0.0.1:11223;
|
||||
proxy_http_version 1.1;
|
||||
proxy_set_header Upgrade $http_upgrade;
|
||||
proxy_set_header Connection "upgrade";
|
||||
proxy_set_header Host $host;
|
||||
proxy_set_header X-Real-IP $remote_addr;
|
||||
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
|
||||
proxy_read_timeout 3600s;
|
||||
}
|
||||
NGINX_REF
|
||||
printf '\033[0m'
|
||||
printf ' 内置 nginx 已处理全部路由,无需再配置各服务端口。\n'
|
||||
printf '\n \033[1;33m注意(多层 nginx 代理):\033[0m\n'
|
||||
printf ' 如上层 nginx 还有多层代理指向 192.168.128.88,\033[1m每一层\033[0m都必须透传 WebSocket 升级头:\n'
|
||||
printf '\n \033[1;33m注意(上层 nginx 代理 WebSocket):\033[0m\n'
|
||||
printf ' 上层 nginx 指向本机 IP:80 即可,\033[1m无需在宿主机配置 nginx\033[0m。\n'
|
||||
printf ' 但上层每一层 nginx 的 location 块都必须有以下四行透传 WebSocket 升级头:\n'
|
||||
printf '\033[0;37m'
|
||||
cat <<'WS_NOTE'
|
||||
proxy_http_version 1.1;
|
||||
@ -807,4 +792,4 @@ printf '\033[0m'
|
||||
printf ' 缺少这四行,IM WebSocket 握手将在任意一层失败。\n'
|
||||
printf '\n \033[1m部署目录:\033[0m %s\n' "$ROOT_DIR"
|
||||
printf ' \033[1m审计日志:\033[0m %s/logs/audit.log\n' "$ROOT_DIR"
|
||||
printf '\n\033[1;32m 部署成功!在所有 nginx 层配置好后即可访问:%s\033[0m\n\n' "${CONSOLE_BASE}"
|
||||
printf '\n\033[1;32m 部署成功!上层 nginx proxy_pass 指向本机 IP:80 后即可访问:%s\033[0m\n\n' "${CONSOLE_BASE}"
|
||||
|
||||
正在加载...
在新工单中引用
屏蔽一个用户