Home >Backend Development >PHP Tutorial >thinkphp nginx php-fpm url rewrite causes 404 error

thinkphp nginx php-fpm url rewrite causes 404 error

WBOY
WBOYOriginal
2016-07-29 09:12:361251browse

thinkphp nginx php-fpm url rewrite causes 404 error

The thinkphp system was previously deployed on apache. Considering that nginx is much more powerful than apache in terms of concurrency performance, the thinkphp system was redeployed on centos in nginx+php-fpm mode. , and found results such as

1

/index.php/home/user/verify

This kind of url nginx will report a 404 error, but change it to

1

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

, which shows that I was able to access it later. The former URL is not supported by nginx, so why? Will it be supported? To solve this problem, you must first understand the several url modes of thinkPHP.

thinkPHP URL pattern

1. pathinfo pattern

1

/index.php/home/user /verify

This URL format requires the server to support pathinfo

2. rewrite mode

1

/ ?s=/home/user/verify

Remove the 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 the file /Application/Common/conf.php

1

'URL_MODEL'=>3

nginx pathinfo mode configuration

nginx does not support pathinfo mode by default Yes, you need to manually add rewrite rules to support

1. Open the site configuration file in the /nginx/conf/vhost directory.

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

1

234567891011

#With uri

location

~^/index.php (.*)                                                                               ​​

if

(!-e

$request_filename)

                                                                                 Write in normal mode                          (.*)$

/

index.php?s

=

$1 last;

}                   }

3. Reload nginx configuration information

1

service nginx reload

Done!

The above introduces the 404 error caused by thinkphp nginx php-fpm url rewrite, including the application content. I hope it will be helpful to friends who are interested in PHP tutorials.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn