Home  >  Article  >  Backend Development  >  nginx支持thinkphp的pathinfo解决方法

nginx支持thinkphp的pathinfo解决方法

WBOY
WBOYOriginal
2016-06-13 12:08:441021browse

nginx支持thinkphp的pathinfo
现在发现问题有两个:
1 不支持PATHINFO。
         localhost/?m=login可以访问,localhost/login不能访问。
2 THINKPHP的U方法生成的地址错误。
         U('login/index')生成的地址是/login-index.html。

nginx配置文件:
location ~ \.php$ {
            root           D:/AppServ/www;
            fastcgi_pass   127.0.0.1:9000;
            fastcgi_index  index.php;
            fastcgi_param  SCRIPT_FILENAME $document_root$fastcgi_script_name;

            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_NAME $real_script_name;
            fastcgi_param  PATH_INFO $path_info; 

            include        fastcgi_params;
        }

.htacess:

RewriteEngine on
RewriteRule ^(.*)$ index.php/$1 last


nginx错误日志:
         2014/10/27 13:54:42 [error] 5404#5668: *107 CreateFile() "D:/AppServ/www/login" failed (2: The system cannot find the file specified), client: 127.0.0.1, server: localhost, request: "GET /login HTTP/1.1", host: "localhost"

------解决思路----------------------

server {<br />       listen  80;<br />       server_name     www.phpno.com;<br />       root /home/www/www_phpno_com/admin_wwwroot;<br />       access_log off;<br />       error_page 404  /404.html;<br />       location /404.html {<br />               root /home/www/www_phpno_com/admin_wwwroot;<br />       }<br />       location /{<br />               index index.html index.htm index.php;<br />               if (-e $request_filename) {<br />                       break;<br />               }<br />               if (!-e $request_filename) {<br />                       rewrite ^/(.*)$ /index.php/$1 last;<br />                       break;<br />               }<br />       }<br /> <br />       location ~ .+\.php($<br><font color='#FF8000'>------解决思路----------------------</font><br>/) {<br />           root           /home/www/www_phpno_com/admin_wwwroot;<br />           fastcgi_index index.php;<br />           fastcgi_split_path_info ^(.+\.php)(.*)$;<br />           fastcgi_param   SCRIPT_FILENAME $document_root$fastcgi_script_name;<br />           fastcgi_param   PATH_INFO               $fastcgi_path_info;<br />           fastcgi_param   PATH_TRANSLATED $document_root$fastcgi_path_info;<br />           fastcgi_pass   127.0.0.1:9000;<br />           include        fastcgi_params;<br />       }<br />   }
自己对比一下

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn