Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

    location ~ .php$ {
        fastcgi_pass   0.0.0.0:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/index.php;
        include        fastcgi_params;
        break;
    } 
    
    location / { 
        rewrite ^/ /index.php break;
    }  
   
   这样设置 访问php页面会直接下载php文件
   
   但是不重定向
   location / { 
        index index.php
    }  
   就能够正常执行php文件,头都大了,不知道为什么。 
   

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
550 views
Welcome To Ask or Share your Answers For Others

1 Answer

应该是把break改成last就好了

 location / { 
        rewrite ^/ /index.php break;
    }  
    

你的这一段意思为,将所有的uri转发请求重写为index.php 然后break,新的重写后的uri(在这个列子被重写为index.php)不会再去匹配下面这个location,所以你的php文件没有传递给php-fpm去解析。但是换成last以后,新的uri会重新匹配符合条件的location,所以index.php被传递给php-fpm解析执行了。

  location ~ .php$ {
        fastcgi_pass   0.0.0.0:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root/index.php;
        include        fastcgi_params;
        break;
    } 
    

如果不明白,毛遂自荐自己的一篇博客。http://blog.csdn.net/fantexi1...


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...