Ubuntu nginx configuration thinkphp pathinfo and URL rewrite mode _nginx

Source: Internet
Author: User
Tags fpm nginx server

Overview

In the previous article Nginx configuration thinkphp support URL Rewrite has described how to configure Nginx thinkphp URL Rewrite, but for some special reasons, this is the CentOS platform. The server environment must use Ubuntu, originally thought and cetons in the same, but the configuration finished found can not use, so on Baidu some articles.

Configuration method
TP Official Solution

Copy Code code as follows:

Location ~. php
{
#原有代码

#定义变量 $path _info, for storing pathinfo information
Set $path _info "";
#定义变量 $real _script_name, for storing real addresses
Set $real _script_name $fastcgi _script_name;
#如果地址与引号内的正则表达式匹配
if ($fastcgi _script_name ~ "^ (. +?\.php) (/.+) $") {
#将文件地址赋值给变量 $real _script_name
Set $real _script_name $;
#将文件地址后的参数赋值给变量 $path _info
Set $path _info $;
}
#配置fastcgi的一些参数
Fastcgi_param script_filename $document _root$real_script_name;
Fastcgi_param script_name $real _script_name;
Fastcgi_param path_info $path _info;
}

In this way, the Nginx server can support PathInfo. However, you also need to configure the rewrite rule if you want to support the thinkphp Url_mode set to 2 mode. Locate the Access_log statement, and add the following statement above it:
Copy Code code as follows:

#如果请求既不是一个文件, not a directory, then execute the rewrite rule
if (!-e $request _filename)
{
#地址作为将参数rewrite到index. php.
Rewrite ^/(. *) $/index.php/$1;
#若是子目录则使用下面这句, change the subdir to the directory name.
#rewrite ^/subdir/(. *) $/subdir/index.php/$1;
}

User Solutions
Copy Code code as follows:

Location/{
root/var/www;
# Attempt to serve request as file, then
# as Directory, then fall back to index.html
Try_files $uri $uri//index.html;
# Uncomment to enable NAXSI on this location
# Include/etc/nginx/naxsi.rules
if (!-e $request _filename)
{
Rewrite ^/phpparser/(. *) $/phpparser/index.php?s=$1 last;
Break
}
}

Then add the following two lines to the localhost ~. php{} Configuration column:

Copy Code code as follows:

Fastcgi_split_path_info ^ (. +\.php) (. *) $;
Fastcgi_param path_info $fastcgi _path_info;

The full configuration is as follows:
Copy Code code as follows:

Location ~ \.php$ {
root/var/www;
Try_files $uri = 404;
Fastcgi_split_path_info ^ (. +\.php) (/.+) $;
# # Note:you should have "cgi.fix_pathinfo = 0;" In php.ini
#
# # with php5-cgi alone:
#fastcgi_pass 127.0.0.1:9000;
Fastcgi_split_path_info ^ (. +\.php) (. *) $;
Fastcgi_param path_info $fastcgi _path_info;
# # with PHP5-FPM:
Fastcgi_pass Unix:/var/run/php5-fpm.sock;
Fastcgi_index index.php;
Include Fastcgi_params;
}

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.