nginx php 文件未找到,ThinkPHP在nginx下运行出错-找不到文件解决办法

1

2

3

4

5

6

7

8

9

10

11

#RewriteEngine on

#RewriteRule ^index.html$ index.php/Index/index

#RewriteRule ^([A-Z][a-z]+).html$ index.php/$1/index

#RewriteRule ^([A-Z][a-z]+)-([a-z]+).html$ index.php/$1/$2

#RewriteRule ^([A-Z][a-z]+)-([a-z]+)-([a-z]+)-([0-9]+).html$

index.php/$1/$2/$3/$4

#RewriteRule

^([A-Z][a-z]+)-([a-z]+)-([a-z]+)-([\x00-\xff]+)-([a-z]+)-([0-9]+)-([a-z]+)-([0-9]+).html$

index.php/$1/$2/$3/$4/$5/$6/$7/$8 rewrite ^(.*)/index.html$

$1/index.php/Index/index;

rewrite ^(.*)/([A-Z][a-z]+).html$ $1/index.php/$2/index;

rewrite ^(.*)/([A-Z][a-z]+)-([a-z]+).html$

$1/index.php/$2/$3;

rewrite ^(.*)/([A-Z][a-z]+)-([a-z]+)-([a-z]+)-([0-9]+).html$

$1/index.php/$2/$3/$4/$5;

rewrite

^(.*)/([A-Z][a-z]+)-([a-z]+)-([a-z]+)-([\x00-\xff]+)-([a-z]+)-([0-9]+)-([a-z]+)-([0

-9]+).html$ $1/index.php/$2/$3/$4/$5/$6/$7/$8/$9;

ThinkPHP支持通过PATHINFO和URL rewrite的方式来提供友好的URL,只需要在配置文件中设置

'URL_MODEL' => 2

即可。在Apache下只需要开启mod_rewrite模块就可以正常访问了,但是Nginx中默认是不支持PATHINFO的,所以我们需要修改nginx.conf文件。

网上搜了很多方法都不奏效,研究了一天,发现通过以下的配置可以完美支持 'URL_MODEL' =>

2 的情况了

location /project/ {

index index.php;

if (!-e $request_filename) {

rewrite ^/project/(.*)$ /project/index.php/$1 last;

break;

}

}

location ~ .+\.php($|/) {

set $script $uri;

set $path_info "/";

if ($uri ~ "^(.+\.php)(/.+)") {

set $script $1;

set $path_info $2;

}

fastcgi_pass 127.0.0.1:9000;

fastcgi_index index.php?IF_REWRITE=1;

include /APMServ/nginx/conf/fastcgi_params;

fastcgi_param PATH_INFO $path_info;

fastcgi_param SCRIPT_FILENAME $document_root/$script;

fastcgi_param SCRIPT_NAME $script;

}

这里先把project下的请求都转发到index.php来处理,亦即ThinkPHP的单一入口文件;然后把对php文件的请求交给fastcgi来处理,并且添加对PATH_INFO的支持。

重启Nginx以后,http://localhost/project/Index/insert,

http://localhost/project/index.php/Index/delete 这样的URL都可以正确访问了。

还有一个地方需要注意的是,Nginx配置文件里 if 和后面的括号之间要有一个空格,不然会报unknown

directive错误。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值