thinkphp nginx php-fpm url rewrite cause 404 error

Source: Internet
Author: User
thinkphp nginx php-fpm url rewrite cause 404 error

The previous thinkphp system was deployed on Apache, considering that the concurrency performance of Nginx was much more powerful than Apache, so the thinkphp system was redeployed in NGINX+PHP-FPM mode on CentOS, and the results found such as

1

/index. PHP/Home/user/verify

This type of URL nginx will report 404 errors, but changed to

1

/index. PHP? s=/home/user/verify

Then can access, this shows that the previous URL Nginx does not support, then why does not support it? To solve this problem, we must first understand the thinkphp of several URL patterns.

thinkphp URL pattern

1. PathInfo mode

1

/index. PHP/Home/user/verify

This URL format requires the server to support PathInfo.

2. Rewrite mode

1

/? s=/home/user/verify

Eliminate pseudo-static mode of index.php

3. Compatibility mode

Normal mode plus s=/parameter/or m=model&a=action

thinkphp URL Mode configuration

Modify the value of Url_model in File/application/common/conf.php

1

' Url_model '=>3

Nginx pathinfo Mode configuration

Nginx default is not support PathInfo mode, you need to manually add rewrite rules to support

1. Open the Site configuration file under the/nginx/conf/vhost directory.

2. Add the following location rule to the server node:

1

2

3

4

5

6

7

8

9

10

11

#以index. URI at the beginning of PHP

Location~^/index. PHP(. *)

{

#如果文件或者路径不存在

if(! -e$request_filename)

{

The URI of the #将 pathinfo mode is rewritten into normal mode

rewrite ^/index. PHP(. *)$ /index. PHP? s=$1 last ;

break;

}

}

3. Re-loading Nginx configuration information

1

Service nginx Reload

Done!

The above describes the thinkphp nginx php-fpm url rewrite caused 404 errors, including the application aspects of the content, I hope that the PHP tutorial interested in a friend helpful.

  • 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.