Files
global-nginx-config/README.md
T
2026-07-10 15:43:49 +08:00

136 lines
3.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# OfferPie 全局 Nginx 网关
单机部署的全局反向代理服务,统一管理 HTTPS 入口。
## 环境说明
生产与测试是**两台隔离的服务器**,各自部署一套网关。两套配置同仓库、同分支,按文件名区分,证书共用泛域名 `*.offerpai.com.cn`
| 环境 | 配置文件 | 编排文件 | 容器名 |
|------|----------|----------|--------|
| 生产 | `nginx.conf` | `docker-compose.yml` | `global-nginx` |
| 测试 | `nginx.test.conf` | `docker-compose.test.yml` | `global-nginx-test` |
两套配置除 `server_name`(域名)外完全一致,proxy_pass 都指向本机 `172.17.0.1:端口`,因此各自打到所在服务器的本地服务。
## 域名映射
### 生产环境
| 域名 | 端口 | 说明 |
|------|------|------|
| www.offerpai.com.cn | 10302 | OfferPie 前端 |
| api.offerpai.com.cn | 10202 | OfferPie Java 后端 API |
| admin.offerpai.com.cn | 10062 | OfferPie 管理后台 Admin |
| ai.offerpai.com.cn | 10502 | OfferPie Python AI 服务 |
### 测试环境
| 域名 | 端口 | 说明 |
|------|------|------|
| test.offerpai.com.cn | 10302 | OfferPie 前端 |
| test-api.offerpai.com.cn | 10202 | OfferPie Java 后端 API |
| test-admin.offerpai.com.cn | 10062 | OfferPie 管理后台 Admin |
| test-ai.offerpai.com.cn | 10502 | OfferPie Python AI 服务 |
未匹配的域名或 IP 访问返回 444(直接断开连接)。
> 注意:测试域名的 DNS 解析需在域名服务商处指向测试服务器 IP,此步骤不在本仓库管理范围内。
## 首次部署(Ubuntu 24
### 1. 更新系统并安装 Docker
```bash
apt update && apt upgrade -y
apt install -y docker.io
systemctl enable docker && systemctl start docker
```
### 2. 安装 Docker Compose
```bash
apt install -y docker-compose-v2
```
### 3. 设置 docker-compose 快捷引用
```bash
echo 'alias docker-compose="docker compose"' >> ~/.bashrc
source ~/.bashrc
```
### 4. 配置 Docker 镜像加速器
```bash
mkdir -p /etc/docker
cat > /etc/docker/daemon.json << 'EOF'
{
"registry-mirrors": [
"https://05f073ad3c0010ea0f4bc00b7105ec20.mirror.swr.myhuaweicloud.com",
"https://aknp1c38.mirror.aliyuncs.com"
]
}
EOF
systemctl restart docker
```
### 5. 配置 Git 记住账号密码
```bash
git config --global credential.helper store
```
### 6. 拉取项目
推荐放在 `/app/` 目录下:
```bash
mkdir -p /app && cd /app
git clone http://git.jianshixingqiu.com/offerpai/global-nginx-config.git
cd global-nginx-config
git checkout master
```
### 7. 启动服务
生产服务器:
```bash
docker compose up -d --build
```
测试服务器:
```bash
docker compose -f docker-compose.test.yml up -d --build
```
## 日常操作
### 更新配置
修改对应环境的配置文件后重新构建:
```bash
# 生产:修改 nginx.conf 后
docker compose up -d --build
# 测试:修改 nginx.test.conf 后
docker compose -f docker-compose.test.yml up -d --build
```
### 证书更新
替换 `certificate/` 目录下的证书文件后重新构建(两套环境共用同一泛域名证书)。
## 文件说明
- `nginx.conf` - 生产环境 Nginx 主配置
- `nginx.test.conf` - 测试环境 Nginx 主配置(仅域名不同)
- `dockerfile` - 生产镜像构建文件
- `Dockerfile.test` - 测试镜像构建文件
- `docker-compose.yml` - 生产容器编排配置
- `docker-compose.test.yml` - 测试容器编排配置
- `certificate/` - SSL 证书目录(泛域名,两套环境共用)