f
This commit is contained in:
30
server/nginx-seo-location-替换片段.conf
Normal file
30
server/nginx-seo-location-替换片段.conf
Normal file
@@ -0,0 +1,30 @@
|
||||
# ========== 在服务器上替换 SEO 的 location 用这一段 ==========
|
||||
#
|
||||
# 步骤:
|
||||
# 1. 宝塔 → 网站 → 找到 www.xingfucha.cn → 设置 → 配置文件
|
||||
# 2. 在配置文件里搜索:__seo__ 或 seo-templates
|
||||
# 3. 删掉旧的 SEO location 块,改成下面「新写法」两段(seo-templates 段 + location / 里的 if+rewrite)
|
||||
# 4. 保存 → SSH 执行 nginx -t && nginx -s reload
|
||||
#
|
||||
# ---------- 新写法(用 root,不依赖 alias)-----------
|
||||
#
|
||||
# 第一段:内部 location(放在 location / 之前)
|
||||
|
||||
location /seo-templates/ {
|
||||
internal;
|
||||
add_header Content-Type "text/html; charset=utf-8";
|
||||
add_header X-SEOMiddleware "nginx-prerendered";
|
||||
}
|
||||
|
||||
# 第二段:在 location / 里必须有(爬虫时重写到上面)
|
||||
|
||||
location / {
|
||||
if ($is_crawler = 1) {
|
||||
rewrite ^ /seo-templates/$seo_file break;
|
||||
}
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
||||
# 说明:root 已在 server 里设为 /www/wwwroot/www.xingfucha.cn,
|
||||
# 请求 /seo-templates/index.html 会读文件 .../seo-templates/index.html
|
||||
# ---------- 结束 ----------
|
||||
Reference in New Issue
Block a user