nginx 配置wordpress固定链接(自定义)

天在wordpress 下配置文章固定链接的时候,遇到了404的错误。我首先在wordpress下的设置里的“固定链接”配置页面,自定义链接的结构 “http://www.haozi8.com/%postname%/,保存更改后,文章无法打开,无论是新编辑的文章还是之前的,都会出现404错误。那么这个问题该如何解决呢?或者说如何在ngix server解决这种问题?

首先我们应该更改网站域名所对应的配置文件,该配置文件的配置可以参照阿里云官方提供的nginx服务器配置视频。 比如本网站域名对应的conf文件为
osetc.com.conf.

默认的配置文件如下:

1
2
3
4
5
6
7
8
9
10
11
12
13
server {
listen       80;
server_name  www.osetc.com;
index index.html index.htm index.php;
root /alidata/www/osetc.com;
//注意此处,将下面的几行if代码copy到这里
location ~ .*.(php|php5)?$
{
#fastcgi_pass  unix:/tmp/php-cgi.sock;
fastcgi_pass  127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi.conf;
}

需要添加的代码:

1
2
3
4
5
6
7
8
9
10
11
if (-f $request_filename/index.html){
rewrite (.*) $1/index.html break;
}

if (-f $request_filename/index.php){
rewrite (.*) $1/index.php;
}

if (!-f $request_filename){
rewrite (.*) /index.php;
}
原文地址:https://www.cnblogs.com/holdon521/p/5675729.html