f
This commit is contained in:
57
server/宝塔Nginx-SEO部署说明.md
Normal file
57
server/宝塔Nginx-SEO部署说明.md
Normal file
@@ -0,0 +1,57 @@
|
||||
# 宝塔环境 Nginx SEO 配置说明
|
||||
|
||||
## 1. 已生成的配置文件
|
||||
|
||||
- **`server/nginx-www.xingfucha.cn.conf`**:在你这套站点上的完整 server 配置(已含 SEO 爬虫检测与静态模板),可直接对照或替换。
|
||||
|
||||
## 2. 部署前准备:上传 SEO 模板
|
||||
|
||||
在服务器上要有 SEO 静态 HTML 目录,路径必须为:
|
||||
|
||||
```text
|
||||
/www/wwwroot/www.xingfucha.cn/seo-templates/
|
||||
```
|
||||
|
||||
操作步骤:
|
||||
|
||||
1. 本地在项目里生成模板(若未生成过):
|
||||
```bash
|
||||
cd server
|
||||
npm run generate
|
||||
```
|
||||
2. 将本地的 **`xfc_webview_V2/public/seo-templates/`** 整个目录上传到服务器,并放到:
|
||||
```text
|
||||
/www/wwwroot/www.xingfucha.cn/seo-templates/
|
||||
```
|
||||
即该目录下应有:`index.html`、`agent.html`、`help.html`、`help-guide.html`、`example.html`、`service.html`、`inquire-*.html` 等。
|
||||
|
||||
## 3. 在宝塔里修改 Nginx 配置
|
||||
|
||||
1. 登录宝塔面板 → **网站** → 找到 **www.xingfucha.cn** → **设置** → **配置文件**(或 **Nginx 配置**)。
|
||||
2. 用下面两种方式之一应用 SEO 修改:
|
||||
- **方式 A(推荐)**:打开 **`server/nginx-www.xingfucha.cn.conf`**,复制其中从 `# ========== SEO 爬虫检测` 到 `# ========== SEO 配置结束` 的整段,以及 **`location ~ ^/__seo__/`** 和 **`location /`** 两个块,按注释位置合并进你当前的 server 配置(保留你原有的 SSL、include、api、日志等)。
|
||||
- **方式 B**:若你当前配置与示例几乎一致,可直接用 **`nginx-www.xingfucha.cn.conf`** 的**整个 server 块**替换当前站点的 server 块(注意先备份原配置)。
|
||||
|
||||
3. 保存后,在宝塔里 **重载 Nginx**(或命令行执行 `nginx -t && nginx -s reload`)。
|
||||
|
||||
## 4. 配置要点说明
|
||||
|
||||
- **爬虫判断**:根据 `User-Agent` 识别百度、Google、必应、360、搜狗、头条、社交媒体等爬虫;识别为爬虫时走 SEO 逻辑。
|
||||
- **路由与模板**:`$uri` 与 `$seo_file` 的对应关系在配置里已写好(如 `/`→index.html,`/agent`→agent.html,`/help`→help.html 等),与 `public/seo-templates` 下文件名一致。
|
||||
- **内部 location**:`/__seo__/` 仅用于内部 `rewrite`,不对外暴露,爬虫看到的仍是正常 URL,只是响应内容来自 `seo-templates` 下的静态 HTML。
|
||||
|
||||
## 5. 验证
|
||||
|
||||
在服务器或本机执行:
|
||||
|
||||
```bash
|
||||
# 应返回带完整 title/description 的 HTML,且响应头有 X-SEOMiddleware
|
||||
curl -sI -A "Baiduspider/2.0" https://www.xingfucha.cn/
|
||||
curl -s -A "Baiduspider/2.0" https://www.xingfucha.cn/ | grep -o '<title>.*</title>'
|
||||
```
|
||||
|
||||
若看到正确的标题和 `X-SEOMiddleware: nginx-prerendered`,说明 SEO 已生效。
|
||||
|
||||
**若验证时得到 404**:说明爬虫未命中 SEO 模板,请按 **`server/如何检测.md`** 里的 **「六、爬虫请求返回 404 时排查」** 在服务器上逐项检查(是否已接入 SEO 配置、`seo-templates` 目录与文件是否存在、alias 路径与 error 日志)。
|
||||
|
||||
更多检测方式见:**`server/如何检测.md`**。
|
||||
Reference in New Issue
Block a user