[VPS] Nginx 规则和WP固定链接的问题

使用DO的默认方式安装,其实挺好的,只是不太懂。

  1. 现在新出现的问题是在安装yoast seo之后,无法查看到sitemap也就是链接https://www.idehe.com/sitemap_index.xml 文件,这样google无法索引到。
  2. 同时尝试修改WP固定链接,变成以下形式,也是出错。好像是报404错误

Post name     https://www.idehe.com/sample-post/

开始解决:

工具顺便换成了xshell, 可以在线修改文件,还行。

检查现有的的nginx conf文件, 发现段落

location / {
try_files $uri $uri/ /index.php;
}

改为

location / {
try_files $uri $uri/ /wp/index.php;
}

其中wp是我的wordpress文件子目录,这样固定链接就没有问题了。

关于try_files的解释是检测文件是否存在,并传递给最后一项。

然后是yoast 的sitemap,网上查找,同样给nginx conf 添加了以下配置。基本是全部拷贝,没有看懂的。。。

# This rewrite redirects sitemap.xml to sitemap_index.xml, which is what Yoast’s WordPress SEO plugin generates. 文件名等同
rewrite ^/sitemap.xml$ /sitemap_index.xml permanent;

# This rewrite ensures that the styles are available for styling the generated sitemap. 我没看懂。。。。
rewrite ^/([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 last;

# These rewrites rule are generated by Yoast’s plugin for Nginx webserver.规则重写, 我没看懂。。。。不过访问/index.php?sitemap=1似乎也可以打开sitemap
rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;