Configuring Nginx Support thinkphp Framework

Source: Internet
Author: User

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


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_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


After modifying the configuration, let's test it.

vi/usr/share/nginx/html/think/application/home/controller/indexcontroller.class.php Modify the Controller file

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

Index index.html index.htm index.php;
if (!-e $request _filename) {
Rewrite ^/(. *) $/index.php/$1 last;
# example
#ModSecurityEnabled on;
Re-start Nginx

Configuring Nginx Support thinkphp Framework

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.