日度归档:2008年12月10日

nginx中SaBlog rewrite规则

 server {
     listen   80;
     server_name  www.phpd.cn *.phpd.cn;
     access_log  /var/log/nginx/phpd.access.log;
     root   /home/phpd/www;
     rewrite ^/show-([0-9]+)-([0-9]+)\.html$ /index.php?action=show&id=$1&page=$2 last;
     rewrite ^/category-([0-9]+)-([0-9]+)\.html$ /index.php?action=index&cid=$1&page=$2 last;
     rewrite ^/archives-([0-9]+)-([0-9]+)\.html$ /index.php?action=index&setdate=$1&page=$2 last;
     rewrite ^/(archives|search|reg|login|index|links)\.html$ /index.php?action=$1 last;
     rewrite ^/(comments|tagslist|trackbacks|index)-([0-9]+)\.html$ /index.php?action=$1&page=$2 last;

     location / {
         index  index.php index.html index.htm;
     }
     location ~ \.php$ {
         fastcgi_pass   127.0.0.1:9000;
         fastcgi_index  index.php;
         fastcgi_param SCRIPT_FILENAME /home/phpd/www$fastcgi_script_name;
         include /etc/nginx/fastcgi_params;
     }
 }

通过修改nginx配置,让nginx支持thinkphp等所需的PATH_INFO

第一种,最简单的方法:

加上一句

location ~ \.php {
         fastcgi_pass 127.0.0.1:9000;
         fastcgi_index index.php;
         fastcgi_param SCRIPT_FILENAME /var/www/company$fastcgi_script_name;
         fastcgi_param  PATH_INFO $fastcgi_script_name;
         include /etc/nginx/fastcgi_params;
}

第二种方法:(注意:nginx 0.5 版此方法无效)

location ~ \.php
              {
                   fastcgi_pass 127.0.0.1:9000;
                   fastcgi_index index.php;
                   set $path_info "";
                   set $real_script_name $fastcgi_script_name;
                   if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") {
                        set $real_script_name $1;
                        set $path_info $2;
                   }
                   fastcgi_param SCRIPT_FILENAME /var/html/$real_script_name;
                   fastcgi_param SCRIPT_NAME $real_script_name;
                   fastcgi_param PATH_INFO $path_info;

                   include /etc/nginx/fastcgi_params;
              }