ThinkPHP支持通过PATHINFO和URL rewrite的方式来提供友好的URL,只需要在配置文件中设置 'URL_MODEL' => 2 即可。在Apache下只需要开启mod_rewrite模块就可以正常访问了,但是Nginx中默认是不支持PATHINFO的,所以我们需要修改nginx.conf文件。
网上搜了很多方法都不奏效,研究了一天,发现通过以下的配置可以完美支持 'URL_MODEL' => 2 的情况了
- server
- {
- listen 80;
- server_name www.xxx.com;
- index index.html index.htm index.php index.shtml;
- root /data2/www/www.xxx.com;
- location / {
- if (!-e $request_filename){
- rewrite ^(.*)$ /index.php?s=/$1 last; #rewrite模式
- rewrite ^(.*)$ /index.php/$1 last; #pathinfo模式 任选其一
- }
- }
- location ~ \.php {
- fastcgi_pass 127.0.0.1:9000;
- fastcgi_split_path_info ^(.+\.php)(.*)$;
- fastcgi_param PATH_INFO $fastcgi_path_info;
- fastcgi_param PATH_TRANSLATED $document_root$fastcgi_path_info;
- fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
- include fastcgi_params;
- fastcgi_connect_timeout 300;
- fastcgi_send_timeout 300;
- fastcgi_read_timeout 300;
- }
- }
转载于:https://blog.51cto.com/chenxiao18/1136647