`
xxbb77
  • 浏览: 4676 次
  • 性别: Icon_minigender_1
  • 来自: 南京
社区版块
存档分类
最新评论

nginx的服务器实现wordpress静态化

 
阅读更多
由于自己新增加了一台nginx的服务器,但是在实现wordpress静态化时吃了很多苦头。

nginx不支持Apache的.htaccess伪静态,官方也没说怎么写nginx的伪静态,所以WP根目录下的.htaccess完全没用了,直接删掉。接下来就是想办法搞定nginx下的WP伪静态了,查了很多国外的资料,因为用Linux版本不一样,lnmp也不一样,nginx的环境配置文件位置也是千奇百怪,最常见的就是wp官网上一帮老外讨论的 /etc/nginx/sites-enabled/,但是这个路径其实WDCP安装好以后根本就没有好嘛。。看了探针原来conf文件都在 /wdlinux/nginx/conf里面,找到Vhost就好办了,可以找到站点的配置文件鸟~

首先的办法就是在nginx-1.0.15/conf下创建一个worpdress.conf文件,写入伪静态规则,然后在站点的conf里面通过include wordpress.conf;引用,然后 service nginxd restart 就好,但是测试了不下30中规则都不行,简直郁闷了!后来看到了“一缕阳光”的这篇博文,恍然大悟,他演示的Ubuntu的,我的CentOS一样适用,修改如下:
server {
        listen       80;
        server_name www.XXX.com www.7760.cn;
        root /mnt/data/www/web/www_XXX_com/public_html;
        index  index.html index.php index.htm;
        error_page  400 /errpage/400.html;
        error_page  403 /errpage/403.html;
        error_page  404 /errpage/404.html;
       location ~ \.php$ {
                fastcgi_pass   127.0.0.1:9000;
                fastcgi_index  index.php;
                include fcgi.conf;
        }

        index index.html index.php;
        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;
        }
    }

然后不要忘记 service nginxd restart重启 就此,WP可以在Nginx上完美运行!注适合/%postname%/固定连接,其他方式没有测试。
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics