存档

文章标签 ‘永久链接’

WordPress静态化配置之Nginx

2009年3月31日 2 条评论

路途志从开博到今天,已经走过了月余。在这一个多月的时间,参考前辈们的经验,对博客进行了大量的定制。其中比较重要的一个工作就是页面静态化—永久链接静态化。在做这个工作的时候,遇到了很大的问题,的服务器是centos5.2+nginx,而公开的资料无一例外都是基于apache的。参考了和apache的案例,经过多次试验终于在Nginx下实现了Wordpress永久链接静态化,Nginx配置文件的server部分加入下列四行:

 

#下面四行斜体字实现链接rewrite,http://www.lutuzhi.com中的所有页面实现了静态化 

rewrite ^/(index|atom|rsd)\.xml$ http://www.lutuzhi.com last;

rewrite ^([_0-9a-zA-Z-]+)?(/wp-.*) $2 last;

rewrite ^([_0-9a-zA-Z-]+)?(/.*\.php)$ $2 last;

  rewrite ^ /index.php last;

完整的server配置如下:

server
{
  listen       80;
  server_name www.lutuzhi.com lutuzhi.com *.lutuzhi.com;
  index index.html index.htm index.php;
  root  /yuluyu/wp;

  #limit_conn   crawler  20;   

  if (!-e $request_filename) {

#下面四行斜体字实现链接rewrite,http://www.lutuzhi.com中的所有页面实现了静态化 

rewrite ^/(index|atom|rsd)\.xml$ http://www.lutuzhi.com last;

rewrite ^([_0-9a-zA-Z-]+)?(/wp-.*) $2 last;

rewrite ^([_0-9a-zA-Z-]+)?(/.*\.php)$ $2 last;

rewrite ^ /index.php last;

  }
  location ~ .*\.(php|php5)?$
  {     
    #fastcgi_pass  unix:/tmp/php-cgi.sock;
    fastcgi_pass  127.0.0.1:9000;
    fastcgi_index index.php;
    include fcgi.conf;
  }
  location ~ .*\.(gif|jpg|jpeg|png|bmp|swf)$
  {
    expires      30d;
  }

  location ~ .*\.(js|css)?$
  {
    expires      1h;
  }   

  log_format  lutuzhi  ‘$remote_addr – $remote_user [$time_local] "$request" ‘
            ‘$status $body_bytes_sent "$http_referer" ‘
            ‘"$http_user_agent" $http_x_forwarded_for’;
  access_log  /yuluyu/logs/lutuzhi.log  lutuzhi;
    }

 

Nginx配置文件更改后,用下列命令更新立即生效:

检查配置文件是否正确:/yuluyu/nginx/sbin/nginx –t
使新配置文件立即生效:kill -HUP `cat /yuluyu/nginx/nginx.pid`


SEO Powered by Platinum SEO from Techblissonline