Two configurations of the thinkphp Nginx rewrite

Source: Internet
Author: User

One, the ordinary way

server {... location/{index index.htm index.html index.php;           #访问路径的文件不存在则重写URL转交给ThinkPHP处理 if (!-e $request _filename) {rewrite ^/(. *) $/index.php/$1 last;        Break }} location ~ \.php/?.        *$ {root/var/www/html/website;        Fastcgi_pass 127.0.0.1:9000;        Fastcgi_index index.php;                #加载Nginx默认 "Server environment variables" configuration include fastcgi.conf;        #设置PATH_INFO并改写SCRIPT_FILENAME, SCRIPT_NAME server environment variable 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; }}

Second, in fact, should be used in a simpler way, the FastCGI module comes with a fastcgi_split_path_info directive specifically designed to solve this kind of problem, the directive will be based on the given regular expression to separate the URL, thus extracting the script name and path info information, Using this directive avoids using the IF statement, which is simpler to configure.
There is also a simpler way to determine if a file exists, using the try_files directive.
server {...    Location/{        index  index.htm index.html index.php;        #如果文件不存在则尝试TP解析        try_files  $uri  /index.php$uri;    }    Location ~. +\.php ($|/) {        root        /var/www/html/website;        Fastcgi_pass   127.0.0.1:9000;        Fastcgi_index  index.php;                #设置PATH_INFO, note that Fastcgi_split_path_info has automatically rewritten the fastcgi_script_name variable,        #后面不需要再改写SCRIPT_FILENAME, Script_ The name environment variable, so you must set        fastcgi_split_path_info  ^ (. +\.php) (/.*) $ before loading fastcgi.conf;        Fastcgi_param  path_info $fastcgi _path_info;                #加载Nginx默认 "Server environment variables" configuration        include        fastcgi.conf;    }}

http://m.blog.csdn.net/article/details?id=18033573

Two configurations of the thinkphp Nginx rewrite

Related Article

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: info-contact@alibabacloud.com 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.