最近在用thinkphp做个小东西,基本完成后部署到nginx服务器上才发觉nginx是不支持pathinfo的,网上搜索了别人的解决方法,有两种思路:
1、修改thinkphp让他可以在nginx上运行
2、修改nginx让它支持pathinfo
网上说nginx开启pathinfo是有一定风险的,能不用pathinfo最好不用,所以还是折腾thinkphp吧,个人觉得这种方法相对第2种方法来得简单
修改nginx的rewrite
location /
{
index index.php;
if (!-e $request_filename)
{
rewrite ^/(.*)$ /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 unix:/tmp/php-cgi.sock;
# fastcgi_pass 127.0.0.1:9000;
include fastcgi.conf;
fastcgi_index index.php?IF_REWRITE=1;
fastcgi_param PATH_INFO $path_info;
fastcgi_param SCRIPT_FILENAME $document_root/$script;
fastcgi_param SCRIPT_NAME $script;
}
然后项目配置下url模式改为2