Files
web/nginx/README.md

71 lines
2.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.
# Nginx 配置(新服务器无 NPM 时使用)
域名:**yuheng.yuxindazhineng.com**,强制 HTTPSSSL 证书按域名单独存放。
## 1. 证书目录(按域名命名)
在服务器上创建专门存放 SSL 的目录,以域名为子目录名:
```bash
sudo mkdir -p /etc/ssl/yh_web/yuheng.yuxindazhineng.com
```
将证书文件放入该目录Let's Encrypt 或自有证书均可):
- **fullchain.pem** — 证书链(或你的 `fullchain.crt`,需在配置里改扩展名)
- **privkey.pem** — 私钥(或你的 `privkey.key`
**一键脚本自动同步**:也可把证书放在项目 **`nginx/`** 下,运行 `./pull-and-restart.sh``./restart.sh` 会自动复制到系统目录。支持两种命名方式:
- **`nginx/yuheng.yuxindazhineng.com.pem`** + **`nginx/yuheng.yuxindazhineng.com.key`**(按域名命名)
- **`nginx/fullchain.pem`** + **`nginx/privkey.pem`**
示例(若用 certbot
```bash
# certbot 默认路径,可复制到统一目录或做软链接
sudo cp /etc/letsencrypt/live/yuheng.yuxindazhineng.com/fullchain.pem /etc/ssl/yh_web/yuheng.yuxindazhineng.com/
sudo cp /etc/letsencrypt/live/yuheng.yuxindazhineng.com/privkey.pem /etc/ssl/yh_web/yuheng.yuxindazhineng.com/
sudo chown -R root:root /etc/ssl/yh_web/yuheng.yuxindazhineng.com
sudo chmod 600 /etc/ssl/yh_web/yuheng.yuxindazhineng.com/privkey.pem
```
## 2. 部署 Nginx 配置
```bash
# 复制项目内配置到 Nginx 配置目录(按实际路径调整)
sudo cp /www/yh_web/nginx/yuheng.yuxindazhineng.com.conf /etc/nginx/conf.d/
# 检查配置
sudo nginx -t
# 重载
sudo systemctl reload nginx
```
若 Nginx 使用其他路径(如 `sites-enabled`),请把上述 conf 放到对应目录并 `include` 到主配置。
## 3. 路由对应关系
| 访问路径 | 后端端口 | 说明 |
|----------|----------|------|
| `https://yuheng.yuxindazhineng.com/` | 9528 | 前台 |
| `https://yuheng.yuxindazhineng.com/admin/` | 9529 | 管理后台 |
| `https://yuheng.yuxindazhineng.com/api/` | 9527 | API |
确保 `docker compose` 已启动,且本机 9527、9528、9529 已监听。
## 4. 新服务器首次安装 Nginx
```bash
# CentOS / RHEL / 阿里云
sudo dnf install -y nginx
# 或
sudo yum install -y nginx
# 开机自启并启动
sudo systemctl enable nginx
sudo systemctl start nginx
```
然后再按上面步骤创建证书目录、放入证书、复制 conf 并重载。