2015-06-17 53 views
1

我添加指令的此块到我的Nginx的安装Nginx的重写和FastCGI - PHP文件获取下载

location ~ \.php$ { 
    try_files $uri =404; 
    fastcgi_split_path_info ^(.+\.php)(/.+)$; 
    # NOTE: You should have "cgi.fix_pathinfo = 0;" in php.ini 
    # With php5-cgi alone: 
    fastcgi_pass unix:/var/run/php5-fpm.sock; 
    # With php5-fpm: 
    include fastcgi.conf; 
    fastcgi_index index.php; 
} 

如果我联系http://myserverip/script.php一切顺利。 我需要使用重写引擎重写某些网址后,指令该块我已经添加了许多其他块这样的:

location = /sentmessages { 
    rewrite ^(.*)$ /sent_messages.php break; 
} 

(我用的.htaccess规则winginx转换器)

如果我联系http://myserverip/sentmessages重写进行的很顺利,但PHP脚本被下载而不是传递给FastCGI。 我不知道如何解决这个问题(试图改变指令顺序没有成功。)

如何解决?谢谢。

+1

删除'break'并阅读文档 –

+0

修复了这个问题。谢谢。 –

回答

0

搜索到Stackoverflow后,解决方案是在重写规则末尾使用“last”。

location = /sentmessages { 
    rewrite ^(.*)$ /sent_messages.php last; 
}