Home  >  Article  >  Backend Development  >  thinkphp nginx php-fpm url rewrite causes 404 error, thinkphpnginx_PHP tutorial

thinkphp nginx php-fpm url rewrite causes 404 error, thinkphpnginx_PHP tutorial

WBOY
WBOYOriginal
2016-07-12 09:05:561130browse

thinkphp nginx php-fpm url rewrite causes 404 error, thinkphpnginx

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. As a result, we found that

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

can be accessed later, which means that the former URL is not supported by nginx, so why is it not supported? To solve this problem, you must first understand the several url modes of thinkPHP.

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

Remove the pseudo-static mode of index.php

3. Compatibility mode

For normal mode, add s=/parameter/ or m=model&a=action

thinkPHP URL pattern 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. 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 2 3 4 5 6 7 8 9 10 11 #以index.php开头的uri location ~ ^/index.php(.*)         {                 #如果文件或者路径不存在                 if (!-e $request_filename)                 {                         #将pathinfo模式的uri重写成普通模式                         rewrite  ^/index.php(.*)$  /index.php?s=$1  last;                         break;                 }         }

3. Reload nginx configuration information

1 service nginx reload

Done!

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1067096.htmlTechArticlethinkphp nginx php-fpm url rewrite causes 404 error, thinkphpnginx thinkphp nginx php-fpm url rewrite causes 404 error before thinkphp The system is deployed on apache, taking into account the concurrency...
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