Nginx配置pathinfo

Nginx默認不支持pathinfo格式的url,最近學習ThinkPHP的URL_MODEL時遇到了這個問題。Apache服務器下開啓rewrite,將AllowOverride設置爲All就ok了,但是Nginx卻需要進一步配置,網上找了很多教程,大都是轉載的比較多,試了好幾個都沒有成功。後來按照另一個教程進行配置,結果ok了。下面是配置過程。

1.Nginx.conf下配置如下

      server
  {
    listen 80;
    server_name test.com;
    index index.php;
    root D:/phpStudy/WWW/test;
     #這裏是開啓rewrite隱藏index.php
     location / {        
       if (!-e $request_filename) { # -e表示存在某個文件或目錄
           rewrite  ^(.*)$  /index.php/$1  last; #last相當於apache中的[L],表示不再往下匹配
               break;
           }
    }
     #這裏是pathinfo的配置
    location ~ \.php {
        fastcgi_pass 127.0.0.1:9000;
        fastcgi_index index.php;
        include fastcgi.conf;
        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 $document_root$real_script_name;
        fastcgi_param SCRIPT_NAME $real_script_name;
        fastcgi_param PATH_INFO $path_info;
    }
  }

2.hosts文件裏配置

127.0.0.1  test.com


ok,打開瀏覽器試下,http://test.com/Home/Index/index,歐拉!

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章