今天来说一下使用 nginx 服务器安装使用 WordPress 站点容易遇到的一个404问题。Nginx 因其异步线程特征,更快、更稳定、支持更多并发连接数,使得越来越多的站长放弃 Apache 改用 Nginx 做为Web服务器,由于 WordPress 固定链接是基于 Apache 的 .htaccess 实现的,并不能直接支持Nginx,好在 WordPress 官方提供了针对Nginx的配置规则。

好了,说下解决方法:

修改 nginx.conf 配置文件,将 location / 节点下添加如下代码:

location / {
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;
}
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;

修改完成保存之后一定记得重启nginx就好了。