最近在用thinkphp做一个项目,基本完成后部署到nginx服务器上才发觉nginx是不支持pathinfo的,网上搜索了别人的解决方法,有两种思路:
方法一、修改thinkphp让他可以在nginx上运行
方法二、修改nginx让它支持pathinfo,网上说nginx开启pathinfo是有一定风险的,能不用pathinfo最好不用,所以还是折腾thinkphp吧,个人觉得这种方法相对第2种方法来得简单
方法一如下:
一、修改对应网站nginx的conf增加rewrite
1 2 3 4 5 6 |
location / { if (!-e $request_filename) { rewrite ^(.*)$ /index.php?s=$1 last; break; } } |
二、然后项目配置下url模式改为2
1 |
'URL_MODEL'=>2, |
三、如果是多个项目,布署项目时要把项目布署到目录里,如后台的项目放到Admin目录里,那么在nginx的rewrite里再写一条
1 2 3 4 5 6 |
location /Admin/ { if (!-e $request_filename) { rewrite ^/Admin/(.*)$ /Admin/index.php?s=$1 last; break; } } |
方法二如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
location / { if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } } location ~ \.php { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; include fcgi.conf; set $real_script_name $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+?\.php)(/.+)$") { set $real_script_name $1; set $path_info $2; } fastcgi_param SCRIPT_FILENAME $document_root$real_script_name; fastcgi_param SCRIPT_NAME $real_script_name; fastcgi_param PATH_INFO $path_info; } |