作者:mobiledu2502896071 | 来源:互联网 | 2023-08-14 10:55
在nginx.conf中的server配置项中添加如下代码:location~.\.php($|){root网站根目录名;set$script$uri;set$
- 在nginx.conf中的server配置项中添加如下代码:
location ~ .+\.php($|/) {root "网站根目录名";set $script $uri;set $path_info "/";if ($uri ~ "^(.+\.php)(/.+)") {set $script $1;set $path_info $2;} fastcgi_pass 127.0.0.1:9000;fastcgi_index index.php?IF_REWRITE=1;include fastcgi.conf;fastcgi_param PATH_INFO $path_info;fastcgi_param SCRIPT_FILENAME $document_root/$script;fastcgi_param SCRIPT_NAME $script;}
ps:root <网站根目录名>这一项很重要&#xff0c;不然会发生无法访问项目文件的错误
2.将thinkphp文件夹放置在网站根目录下&#xff0c;新建index.php
define(&#39;APP_PATH&#39;,&#39;./App/&#39;);
define(&#39;APP_DEBUG&#39;,true);
define(&#39;_PHP_FILE_&#39;,$_SERVER[&#39;SCRIPT_NAME&#39;]);
include_once(&#39;./ThinkPHP/ThinkPHP.php&#39;);
3.重新加载nginx配置文件&#xff1a;
cmd下输入nginx -s reload
4.访问index.php&#xff0c;如http://localhost/index.php,布置成功