Nginx configuration supports ThinkPHP for PATH_INFO
- 2020-05-09 19:58:19
- OfStack
An overview of the
Today, I encountered a problem, Ubuntu+Nginx+MySQL configuration ThinkPHP project, and found that Nginx does not support ThinkPHP's PATH_INFO mode after doing half of it. It took baidu a long time to solve the problem with the help of my friends.
Nginx supports PATH_INFO of ThinkPHP
The environment
14.04 + Nginx + MySQL Ubuntu. All programs are installed via apt-get, so the configuration path for Nginx is /etc/nginx/ sites-available /default.
The solution
Navigate to the following section of the Nginx configuration file:
location / {
# First attempt to serve request as file, then
# as directory, then fall back to displaying a 404.
try_files $uri $uri/ =404;
# Uncomment to enable naxsi on this location
# include /etc/nginx/naxsi.rules
}
Add the following code:
if (!-e $request_filename)
{
rewrite ^/myapp/(.*)$ /myapp/index.php?s=$1 last;
break;
}
Regular writing
When I was trying to solve this problem, I saw several solutions, but I did not know which one was the most standard. I was not familiar with regularization, so I wrote it down first and studied it later:
Regular 1:
rewrite ^/MYAPP/(.*)$ /MYAPP/index.php/$1 last;
Regular 2:
rewrite ^(.*)$ /index.php?s=$1 last;