Nginx上设置WordPress固定连接

不用怀疑,我的确连伪静态都不会。在nginx上弄一个wordpress都找了半天,终于做好。

实际是很简单,可是要配置的代码不止一组。

先找出你网站的.conf文件。一般是在 /etc/nginx/sites-available/你的域名.conf

server {
server_name ctech.cyou www.ctech.cyou;
listen 0.0.0.0
root /home/;
index index.html index.htm index.php;
access_log /var/log/virtualmin/log;
error_log /var/log/virtualmin/log;
   #在这里开始输入以下代码

 

        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,会发现还是无法进入wordpress的初始化设置。这时需要在加入一段代码

#找到location ~ .php这段
location ~ .php(/|$) {
         include fastcgi.conf; #在里面输入这一句
}
#在找到location /你的根目录
location /wordpress {
try_files $uri $uri/ /wordpress/index.php?$args; #加这一句
}

重启nginx,wordpress初始化安装就可以启动了。