f
This commit is contained in:
124
server/DEPLOY.md
124
server/DEPLOY.md
@@ -1,47 +1,33 @@
|
|||||||
# 智能查 SEO 服务部署指南(纯 Nginx 方案)
|
# 智能查 SEO 部署指南(纯 Nginx 方案)
|
||||||
|
|
||||||
## 方案说明
|
|
||||||
|
|
||||||
使用纯 Nginx 配置实现爬虫检测,无需 Node.js 服务器。
|
|
||||||
|
|
||||||
**工作原理:**
|
|
||||||
```
|
|
||||||
请求 → Nginx 检测 User-Agent
|
|
||||||
├─ 是爬虫 → 返回静态 SEO HTML 模板
|
|
||||||
└─ 普通用户 → 返回 SPA 应用
|
|
||||||
```
|
|
||||||
|
|
||||||
## 部署步骤
|
## 部署步骤
|
||||||
|
|
||||||
### 1. 构建前端项目
|
### 1. 本地准备
|
||||||
|
|
||||||
|
确保 SEO 模板已生成:
|
||||||
```bash
|
```bash
|
||||||
cd /www/wwwroot/zhinengcha.cn
|
cd Zncfont_V2/server
|
||||||
npm run build
|
|
||||||
```
|
|
||||||
|
|
||||||
### 2. 生成 SEO 模板到 dist 目录
|
|
||||||
|
|
||||||
```bash
|
|
||||||
cd /www/wwwroot/zhinengcha.cn/server
|
|
||||||
node generate-seo-templates.cjs
|
node generate-seo-templates.cjs
|
||||||
```
|
```
|
||||||
|
|
||||||
生成后目录结构:
|
### 2. 上传文件到服务器
|
||||||
|
|
||||||
|
将以下文件/目录上传到服务器 `/www/wwwroot/zhinengcha.cn/`:
|
||||||
|
|
||||||
```
|
```
|
||||||
dist/
|
zhinengcha.cn/
|
||||||
├── index.html
|
├── index.html # SPA 入口(dist 产物)
|
||||||
├── assets/
|
├── assets/ # 静态资源(dist 产物)
|
||||||
└── seo-templates/
|
└── seo-templates/ # SEO 静态模板(从 public 复制)
|
||||||
├── index.html
|
├── index.html
|
||||||
├── agent.html
|
├── agent.html
|
||||||
├── help.html
|
├── help.html
|
||||||
├── ...
|
└── ...
|
||||||
```
|
```
|
||||||
|
|
||||||
### 3. 修改 Nginx 配置
|
### 3. 修改 Nginx 配置
|
||||||
|
|
||||||
将以下配置复制到宝塔面板的站点配置中:
|
在宝塔面板中,将站点配置修改为以下内容:
|
||||||
|
|
||||||
```nginx
|
```nginx
|
||||||
server
|
server
|
||||||
@@ -55,9 +41,8 @@ server
|
|||||||
listen [::]:80;
|
listen [::]:80;
|
||||||
server_name zhinengcha.cn www.zhinengcha.cn p.zhenaicha.cn;
|
server_name zhinengcha.cn www.zhinengcha.cn p.zhenaicha.cn;
|
||||||
index index.html index.htm default.htm default.html;
|
index index.html index.htm default.htm default.html;
|
||||||
root /www/wwwroot/zhinengcha.cn/dist;
|
root /www/wwwroot/zhinengcha.cn;
|
||||||
#CERT-APPLY-CHECK--START
|
#CERT-APPLY-CHECK--START
|
||||||
# 用于SSL证书申请时的文件验证相关配置 -- 请勿删除并保持这段设置在优先级高的位置
|
|
||||||
include /www/server/panel/vhost/nginx/well-known/zhinengcha.cn.conf;
|
include /www/server/panel/vhost/nginx/well-known/zhinengcha.cn.conf;
|
||||||
#CERT-APPLY-CHECK--END
|
#CERT-APPLY-CHECK--END
|
||||||
|
|
||||||
@@ -74,30 +59,26 @@ server
|
|||||||
add_header Strict-Transport-Security "max-age=31536000";
|
add_header Strict-Transport-Security "max-age=31536000";
|
||||||
add_header Alt-Svc 'quic=":443"; h3=":443"; h3-29=":443"; h3-27=":443";h3-25=":443"; h3-T050=":443"; h3-Q050=":443";h3-Q049=":443";h3-Q048=":443"; h3-Q046=":443"; h3-Q043=":443"';
|
add_header Alt-Svc 'quic=":443"; h3=":443"; h3-29=":443"; h3-27=":443";h3-25=":443"; h3-T050=":443"; h3-Q050=":443";h3-Q049=":443";h3-Q048=":443"; h3-Q046=":443"; h3-Q043=":443"';
|
||||||
error_page 497 https://$host$request_uri;
|
error_page 497 https://$host$request_uri;
|
||||||
|
|
||||||
#SSL-END
|
#SSL-END
|
||||||
|
|
||||||
#ERROR-PAGE-START 错误页配置,可以注释、删除或修改
|
#ERROR-PAGE-START
|
||||||
#error_page 404 /404.html;
|
#error_page 404 /404.html;
|
||||||
#error_page 502 /502.html;
|
#error_page 502 /502.html;
|
||||||
#ERROR-PAGE-END
|
#ERROR-PAGE-END
|
||||||
|
|
||||||
#REWRITE-START URL重写规则引用,修改后将导致面板设置的伪静态规则失效
|
#REWRITE-START
|
||||||
include /www/server/panel/vhost/rewrite/html_zhinengcha.cn.conf;
|
include /www/server/panel/vhost/rewrite/html_zhinengcha.cn.conf;
|
||||||
#REWRITE-END
|
#REWRITE-END
|
||||||
|
|
||||||
#禁止访问的文件或目录
|
|
||||||
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
|
location ~ ^/(\.user.ini|\.htaccess|\.git|\.env|\.svn|\.project|LICENSE|README.md)
|
||||||
{
|
{
|
||||||
return 404;
|
return 404;
|
||||||
}
|
}
|
||||||
|
|
||||||
#一键申请SSL证书验证目录相关设置
|
|
||||||
location ~ \.well-known{
|
location ~ \.well-known{
|
||||||
allow all;
|
allow all;
|
||||||
}
|
}
|
||||||
|
|
||||||
# API 代理
|
|
||||||
location /api/v1 {
|
location /api/v1 {
|
||||||
proxy_pass http://127.0.0.1:21004;
|
proxy_pass http://127.0.0.1:21004;
|
||||||
proxy_set_header Host 127.0.0.1:$server_port;
|
proxy_set_header Host 127.0.0.1:$server_port;
|
||||||
@@ -115,55 +96,44 @@ server
|
|||||||
proxy_set_header Connection "upgrade";
|
proxy_set_header Connection "upgrade";
|
||||||
}
|
}
|
||||||
|
|
||||||
# 前端路由处理 - 爬虫检测返回静态SEO页面
|
|
||||||
location / {
|
location / {
|
||||||
set $seo_page 0;
|
set $is_bot 0;
|
||||||
# 检测常见爬虫 User-Agent
|
|
||||||
if ($http_user_agent ~* "(baiduspider|googlebot|bingbot|msnbot|360spider|sogou|youdaobot|twitterbot|facebookexternalhit|linkedinbot|bytespider)") {
|
if ($http_user_agent ~* "(baiduspider|googlebot|bingbot|msnbot|360spider|sogou|youdaobot|twitterbot|facebookexternalhit|linkedinbot|bytespider)") {
|
||||||
set $seo_page 1;
|
set $is_bot 1;
|
||||||
}
|
}
|
||||||
# 如果是爬虫,返回对应的 SEO 静态页面
|
if ($is_bot = 1) {
|
||||||
if ($seo_page = 1) {
|
|
||||||
rewrite ^/$ /seo-templates/index.html last;
|
rewrite ^/$ /seo-templates/index.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/agent$ /seo-templates/agent.html last;
|
rewrite ^/agent$ /seo-templates/agent.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/help$ /seo-templates/help.html last;
|
rewrite ^/help$ /seo-templates/help.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/help/guide$ /seo-templates/help-guide.html last;
|
rewrite ^/help/guide$ /seo-templates/help-guide.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/example$ /seo-templates/example.html last;
|
rewrite ^/example$ /seo-templates/example.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/service$ /seo-templates/service.html last;
|
rewrite ^/service$ /seo-templates/service.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/inquire/riskassessment$ /seo-templates/inquire-riskassessment.html last;
|
rewrite ^/inquire/riskassessment$ /seo-templates/inquire-riskassessment.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/inquire/companyinfo$ /seo-templates/inquire-companyinfo.html last;
|
rewrite ^/inquire/companyinfo$ /seo-templates/inquire-companyinfo.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/inquire/marriage$ /seo-templates/inquire-marriage.html last;
|
rewrite ^/inquire/marriage$ /seo-templates/inquire-marriage.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/promote$ /seo-templates/promote.html last;
|
rewrite ^/promote$ /seo-templates/promote.html last;
|
||||||
}
|
}
|
||||||
# 普通用户返回 SPA
|
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
# SEO 静态模板目录
|
|
||||||
location /seo-templates {
|
|
||||||
root /www/wwwroot/zhinengcha.cn/dist;
|
|
||||||
internal;
|
|
||||||
}
|
|
||||||
|
|
||||||
#禁止在证书验证目录放入敏感文件
|
|
||||||
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
|
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
|
||||||
return 403;
|
return 403;
|
||||||
}
|
}
|
||||||
@@ -192,23 +162,31 @@ server
|
|||||||
nginx -t && nginx -s reload
|
nginx -t && nginx -s reload
|
||||||
```
|
```
|
||||||
|
|
||||||
## 验证部署
|
## 验证
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
# 模拟百度爬虫访问首页
|
# 模拟百度爬虫
|
||||||
curl -A "Mozilla/5.0 (compatible; Baiduspider/2.0)" https://www.zhinengcha.cn/
|
curl -A "Baiduspider" https://www.zhinengcha.cn/
|
||||||
|
|
||||||
# 模拟 Google 爬虫访问首页
|
# 普通浏览器
|
||||||
curl -A "Mozilla/5.0 (compatible; Googlebot/2.1)" https://www.zhinengcha.cn/
|
curl -A "Chrome" https://www.zhinengcha.cn/
|
||||||
|
|
||||||
# 普通浏览器访问(应返回 SPA)
|
|
||||||
curl -A "Mozilla/5.0 (Windows NT 10.0; Win64; x64) Chrome/120.0.0.0" https://www.zhinengcha.cn/
|
|
||||||
```
|
```
|
||||||
|
|
||||||
## 更新 SEO 配置
|
## 服务器目录结构
|
||||||
|
|
||||||
当修改 `useSEO.js` 中的 TDK 配置后:
|
```
|
||||||
|
/www/wwwroot/zhinengcha.cn/
|
||||||
1. 同步更新 `server/generate-seo-templates.cjs` 中的 `pageSEOConfigs`
|
├── index.html
|
||||||
2. 重新生成模板:`node generate-seo-templates.cjs`
|
├── assets/
|
||||||
3. 重新部署 `dist` 目录
|
└── seo-templates/
|
||||||
|
├── index.html
|
||||||
|
├── agent.html
|
||||||
|
├── help.html
|
||||||
|
├── help-guide.html
|
||||||
|
├── example.html
|
||||||
|
├── service.html
|
||||||
|
├── inquire-riskassessment.html
|
||||||
|
├── inquire-companyinfo.html
|
||||||
|
├── inquire-marriage.html
|
||||||
|
└── promote.html
|
||||||
|
```
|
||||||
|
|||||||
@@ -215,7 +215,7 @@ ${JSON.stringify(structuredData, null, 8)}
|
|||||||
* 主函数
|
* 主函数
|
||||||
*/
|
*/
|
||||||
function main() {
|
function main() {
|
||||||
const outputDir = path.join(__dirname, '../dist/seo-templates')
|
const outputDir = path.join(__dirname, '../public/seo-templates')
|
||||||
|
|
||||||
// 创建输出目录
|
// 创建输出目录
|
||||||
if (!fs.existsSync(outputDir)) {
|
if (!fs.existsSync(outputDir)) {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ server
|
|||||||
listen [::]:80;
|
listen [::]:80;
|
||||||
server_name zhinengcha.cn www.zhinengcha.cn p.zhenaicha.cn;
|
server_name zhinengcha.cn www.zhinengcha.cn p.zhenaicha.cn;
|
||||||
index index.html index.htm default.htm default.html;
|
index index.html index.htm default.htm default.html;
|
||||||
root /www/wwwroot/zhinengcha.cn/dist;
|
root /www/wwwroot/zhinengcha.cn;
|
||||||
#CERT-APPLY-CHECK--START
|
#CERT-APPLY-CHECK--START
|
||||||
# 用于SSL证书申请时的文件验证相关配置 -- 请勿删除并保持这段设置在优先级高的位置
|
# 用于SSL证书申请时的文件验证相关配置 -- 请勿删除并保持这段设置在优先级高的位置
|
||||||
include /www/server/panel/vhost/nginx/well-known/zhinengcha.cn.conf;
|
include /www/server/panel/vhost/nginx/well-known/zhinengcha.cn.conf;
|
||||||
@@ -71,53 +71,46 @@ server
|
|||||||
|
|
||||||
# 前端路由处理 - 爬虫检测返回静态SEO页面
|
# 前端路由处理 - 爬虫检测返回静态SEO页面
|
||||||
location / {
|
location / {
|
||||||
set $seo_page 0;
|
set $is_bot 0;
|
||||||
# 检测常见爬虫 User-Agent
|
# 检测常见爬虫 User-Agent
|
||||||
if ($http_user_agent ~* "(baiduspider|googlebot|bingbot|msnbot|360spider|sogou|youdaobot|twitterbot|facebookexternalhit|linkedinbot|bytespider)") {
|
if ($http_user_agent ~* "(baiduspider|googlebot|bingbot|msnbot|360spider|sogou|youdaobot|twitterbot|facebookexternalhit|linkedinbot|bytespider)") {
|
||||||
set $seo_page 1;
|
set $is_bot 1;
|
||||||
}
|
}
|
||||||
# 如果是爬虫且是首页
|
# 爬虫访问各页面返回对应 SEO 模板
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/$ /seo-templates/index.html last;
|
rewrite ^/$ /seo-templates/index.html last;
|
||||||
}
|
}
|
||||||
# 如果是爬虫且是其他页面
|
if ($is_bot = 1) {
|
||||||
if ($seo_page = 1) {
|
|
||||||
rewrite ^/agent$ /seo-templates/agent.html last;
|
rewrite ^/agent$ /seo-templates/agent.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/help$ /seo-templates/help.html last;
|
rewrite ^/help$ /seo-templates/help.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/help/guide$ /seo-templates/help-guide.html last;
|
rewrite ^/help/guide$ /seo-templates/help-guide.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/example$ /seo-templates/example.html last;
|
rewrite ^/example$ /seo-templates/example.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/service$ /seo-templates/service.html last;
|
rewrite ^/service$ /seo-templates/service.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/inquire/riskassessment$ /seo-templates/inquire-riskassessment.html last;
|
rewrite ^/inquire/riskassessment$ /seo-templates/inquire-riskassessment.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/inquire/companyinfo$ /seo-templates/inquire-companyinfo.html last;
|
rewrite ^/inquire/companyinfo$ /seo-templates/inquire-companyinfo.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/inquire/marriage$ /seo-templates/inquire-marriage.html last;
|
rewrite ^/inquire/marriage$ /seo-templates/inquire-marriage.html last;
|
||||||
}
|
}
|
||||||
if ($seo_page = 1) {
|
if ($is_bot = 1) {
|
||||||
rewrite ^/promote$ /seo-templates/promote.html last;
|
rewrite ^/promote$ /seo-templates/promote.html last;
|
||||||
}
|
}
|
||||||
# 普通用户返回 SPA
|
# 普通用户返回 SPA
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
||||||
# SEO 静态模板目录
|
|
||||||
location /seo-templates {
|
|
||||||
root /www/wwwroot/zhinengcha.cn/dist;
|
|
||||||
internal;
|
|
||||||
}
|
|
||||||
|
|
||||||
#禁止在证书验证目录放入敏感文件
|
#禁止在证书验证目录放入敏感文件
|
||||||
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
|
if ( $uri ~ "^/\.well-known/.*\.(php|jsp|py|js|css|lua|ts|go|zip|tar\.gz|rar|7z|sql|bak)$" ) {
|
||||||
return 403;
|
return 403;
|
||||||
|
|||||||
@@ -63,16 +63,17 @@ const currentStatus = !actualData
|
|||||||
:class="`status-label rounded-full px-6 py-3 text-center font-bold shadow-md ${currentStatus.bgClass} ${currentStatus.textClass}`">
|
:class="`status-label rounded-full px-6 py-3 text-center font-bold shadow-md ${currentStatus.bgClass} ${currentStatus.textClass}`">
|
||||||
{{ currentStatus.text }}
|
{{ currentStatus.text }}
|
||||||
</div>
|
</div>
|
||||||
<div v-if="currentStatus.opDate" class="op-date-container mt-4 px-4 py-2 bg-blue-50 rounded-lg border border-blue-200">
|
|
||||||
<p class="op-date text-sm font-medium text-blue-700">
|
|
||||||
登记日期:{{ currentStatus.opDate }}
|
|
||||||
</p>
|
|
||||||
</div>
|
|
||||||
<p v-html="currentStatus.description" class="status-description mt-3 text-sm text-gray-600"></p>
|
<p v-html="currentStatus.description" class="status-description mt-3 text-sm text-gray-600"></p>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
<!-- <div v-if="currentStatus.opDate" class="op-date-container mt-4 px-4 py-2 bg-blue-50 rounded-lg border border-blue-200">
|
||||||
|
<p class="op-date text-sm font-medium text-blue-700">
|
||||||
|
登记日期:{{ currentStatus.opDate }}
|
||||||
|
</p>
|
||||||
|
</div> -->
|
||||||
|
|
||||||
<style lang="scss" scoped>
|
<style lang="scss" scoped>
|
||||||
.status-info {
|
.status-info {
|
||||||
|
|||||||
Reference in New Issue
Block a user