通过修改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;
              }

通过修改nginx配置,让nginx支持thinkphp等所需的PATH_INFO》有7个想法

  1. xzy

    [quote=ahu]第一种方法是无效的吧~[/quote]
    是有效的,但我是在0.5上面试的,,已通过测试

  2. fhc

    第一种方法中
    location ~ \.php$ {
    不对
    应该是
    location ~ \.php {

    $结尾后匹配不了index.php/xx/这样的URL

  3. xzy

    [quote=fhc]第一种方法中
    location ~ \.php$ {
    不对
    应该是
    location ~ \.php {
    $结尾后匹配不了index.php/xx/这样的URL[/quote]

    没错,,,应该是 location ~ \.php {
    因为我每个index.php/abc
    都单独写了rewrite,所以没注意到!!

  4. xfstart07

    请问,我两种方法都试了,还是不行,而且出现了Restarting nginx: nginx: [warn] conflicting server name “localhost” on 0.0.0.0:80, ignored
    这是为什么啊?

  5. ℃冻番茄 文章作者

    if (!-e $request_filename)
    {
    rewrite ^/(.*)$ /index.php/$1 last;
    break;
    }
    location ~ .*\.php(.*)$
    {
    fastcgi_pass unix:/tmp/php-cgi.sock;
    fastcgi_index index.php;
    include fcgi.conf;
    fastcgi_split_path_info ^(.+\.php)(.*)$;
    include fastcgi_params;
    fastcgi_param PATH_INFO $fastcgi_path_info;
    }

评论已关闭。