概述
今天遇到一个问题,Ubuntu+Nginx+MySQL配置ThinkPHP的项目,做了一半发现,Nginx不支持ThinkPHP的PATH_INFO模式,百度了好久,在朋友的帮忙下才解决,记录下。
Nginx支持ThinkPHP的PATH_INFO
环境
Ubuntu 14.04+Nginx+MySQL。所有程序都是通过apt-get安装的,所以Nginx的配置文件路径在/etc/nginx/sites-available/default。
解决方法
定位到Nginx配置文件的如下部分:
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
}
# 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
}
加入下面的代码:
if (!-e $request_filename)
{
rewrite ^/myapp/(.*)$ /myapp/index.php?s=$1 last;
break;
}
正则的写法
解决这个问题的时候,看到了好几种解决方案,光正则就看到了好几个,也不知道到底哪个是最标准的,本人正则也不是很熟,先记录下来,以后慢慢研究:
正则1:
rewrite ^/MYAPP/(.*)$ /MYAPP/index.php/$1 last;
正则2:
rewrite ^(.*)$ /index.php?s=$1 last;
本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!