Because Nginx does not natively support pathinfo, it is not possible to use the thinkphp framework, but we can modify it in the configuration to make it work properly thinkphp.
1. Modify Configuration Support PathInfo
Vi/etc/nginx/cong.d/default.conf
Add in Nginx Configuration
Location ~ \.php/?. *$ {
root HTML; #这里的路径需要注意一下, the previous configuration errors were due to the wrong path being pasted directly from the Web.
Fastcgi_pass 127.0.0.1:9000;
Fastcgi_index index.php;
Include fastcgi.conf;
Set $fastcgi _script_name2 $fastcgi _script_name;
if ($fastcgi _script_name ~ "^ (. +\.php) (/.+) $") {
Set $fastcgi _script_name2 $;
Set $path _info;
}
Fastcgi_param path_info $path _info;
Fastcgi_param script_filename $document _root$fastcgi_script_name2;
Fastcgi_param script_name $fastcgi _script_name2;
}
Restart Nginx,service nginx Restart
Test:
After modifying the configuration, let's test it.
vi/usr/share/nginx/html/think/application/home/controller/indexcontroller.class.php Modify the Controller file
<?php
namespace Home\controller;
Use Think\controller;
Class Indexcontroller extends Controller {
Public Function index () {
$this->display ();
}
}
Create template file again, vi/usr/share/nginx/html/think/application/home/view/index/index.html
Write a little something: Hello,world
Access Address: ###/think/index.php/home/index/index.html
Shows the Hello,world, indicating the configuration is successful.
2. We often use URL rewriting mode in the thinkphp framework, so let's configure the rewrite
Location/{
root/usr/share/nginx/html;
Index index.html index.htm index.php;
if (!-e $request _filename) {
Rewrite ^/(. *) $/index.php/$1 last;
Break
}
# example
#ModSecurityEnabled on;
#ModSecurityConfig/etc/nginx/modsecurity.conf;
}
Re-start Nginx
Configuring Nginx Support thinkphp Framework