在LNMP环境下的wordpress,在wordpress后台配置链接,使用非默认链接格式时,会出现无法访问的情况。
网上解决方案一:
进入lnmp默认安装目录的配置目录/usr/local/nginx/conf
这个目录下面有个nginx.conf配置文件
打开nginx.conf文件,找到server字段
在server字段的 root /home/wwwroot/default这一行下面添加下面的代码
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;}
网上解决方案二:
在nginx的conf.d文件夹下创建个wordpress.conf ,将下面的代码粘贴进去:
location / {
try_files $uri $uri/ /index.php?$args;
}
rewrite /wp-admin$ $scheme://$host$uri/ permanent;
然后在nginx虚拟机配置文件在 conf/vhost/www.dabu.info.conf 。同样,在root 那行下面,添加一行:
include wordpress.conf;
然后重启nginx服务器;
我的方案:
直接在conf.d 文件夹中 找到wordpress的nginx的配置文件,在
location / {
index index.php index.html index.htm;
#如果请求既不是一个文件,也不是一个目录,则执行一下重写规则
if (!-e $request_filename)
{
rewrite (.*) /index.php;
}
}
把所有的请求转到index.php,利用wordpress的路由规则来重定向