lnmp配置支持thinkphp和nginx路由url重写

时间:2023-07-22 19:11:50

ThinkPHP3.2.3项目放到lnmp环境之后只能打开首页,或者通过传参方式打开控制器,否则就一直显示404页面。搞了一上午,终于解决了

step1:

修改php.ini

cgi.fix_pathinfo=1

step2:

修改nginx.conf或者vhost/*.conf

注释掉include enable-php.conf

添加include enable-php-pathinfo.conf

step3:

加入重写规则

location / {
if (!-e $request_filename) { rewrite ^/index.php(.*)$ /index.php?s=$1 last;
rewrite ^(.*)$ /index.php?s=$1 last;
break;
}
index index.html index.htm index.php l.php;
autoindex off;
}

step4:

重启lnmp:

lnmp restart