nginx上部署thinkphp的解決方案
nginx上部署thinkphp的解決方案
?
最近在用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
'URL_MODEL'=>2,
如果是多重專案,布署項目時要把項目布署到目錄裡,如背景項目放到Admin目錄裡,那麼在nginx的rewrite裡再寫一條
?
location?/XXX/?{
if?(!-e?$request_filename)?{
rewrite??^/XXX/(.*)$??/XXX/index.php?s=$1??last;
break;
}
}