Home > Backend Development > PHP Tutorial > nginx上部署thinkphp的解决办法

nginx上部署thinkphp的解决办法

WBOY
Release: 2016-06-13 12:40:43
Original
818 people have browsed it

nginx上部署thinkphp的解决方法

nginx上部署thinkphp的解决方法

最近在用thinkphp做个小东西,基本完成后部署到nginx服务器上才发觉nginx是不支持pathinfo的,网上搜索了别人的解决方法,有两种思路:
1、修改thinkphp让他可以在nginx上运行
2、修改nginx让它支持pathinfo

网上说nginx开启pathinfo是有一定风险的,能不用pathinfo最好不用,所以还是折腾thinkphp吧,个人觉得这种方法相对第2种方法来得简单

修改nginx的rewrite

location /<br style="padding: 0px; margin: 0px; border: 0px none;">{<br style="padding: 0px; margin: 0px; border: 0px none;">index index.php;<br style="padding: 0px; margin: 0px; border: 0px none;">if (!-e $request_filename)<br style="padding: 0px; margin: 0px; border: 0px none;">{<br style="padding: 0px; margin: 0px; border: 0px none;">rewrite ^/(.*)$ /index.php/$1 last;<br style="padding: 0px; margin: 0px; border: 0px none;">break;<br style="padding: 0px; margin: 0px; border: 0px none;">}<br style="padding: 0px; margin: 0px; border: 0px none;">}

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/?{<br style="padding: 0px; margin: 0px; border: 0px none;">if?(!-e?$request_filename)?{<br style="padding: 0px; margin: 0px; border: 0px none;">rewrite??^/XXX/(.*)$??/XXX/index.php?s=$1??last;<br style="padding: 0px; margin: 0px; border: 0px none;">break;<br style="padding: 0px; margin: 0px; border: 0px none;">}<br style="padding: 0px; margin: 0px; border: 0px none;">}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template