nginx要怎么配置rewrite才能运行vephp、yii和thinkphp等MVC框架
《nginx要怎么配置rewrite才能运行vephp、yii和thinkphp等MVC框架?》要点: 网络上很多配置nginx的rewrite其实是不可用的,如果想运行vephp、yii、thinkphp等MVC框架,在apache下是很容易的,nginx比较麻烦。 下面这个配置是已应用于vephp框架( www.52php.cn ),并且对thinkphp也是可用的。并且window和linux通用,只是要把根目录替换一下。 它的原理是:如果服务器上存在该脚本文件就直接访问,如果不存在,则使用MVC框架路由解析。 特分享出来。 server { listen 80; server_name www.52php.cn;
#charset koi8-r; #access_log logs/host.access.log main; #root /var/www/website; # linux下根目录 root M:/www/website; #window下根目录 index index.html index.htm index.php;
location ~ .(css|js|jpg|jpeg|png|bmp|gif|svg|ttf|woff|woff2|eot|otf|ico|css.map|min.map)(.*)$ { break; }
location / { #index index.htm index.html index.php; #访问路径的文件不存在则重写URL转交给框架处理 if (!-e $request_filename) { rewrite ^/(.*)$ /index.php/$1 last; break; } }
location ~ .php/?.*$ { fastcgi_pass 127.0.0.1:9000; fastcgi_index index.php; #加载Nginx默认"服务器环境变量"配置 #include fastcgi.conf; include fastcgi_params;
#设置PATH_INFO并改写SCRIPT_FILENAME,SCRIPT_NAME服务器环境变量 set $fastcgi_script_name2 $fastcgi_script_name; if ($fastcgi_script_name ~ "^(.+.php)(/.+)$") { set $fastcgi_script_name2 $1; set $path_info $2; } fastcgi_param PATH_INFO $path_info; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name2; fastcgi_param SCRIPT_NAME $fastcgi_script_name2; }
error_page 404 /404.html;
# redirect server error pages to the static page /50x.html #error_page 500 502 503 504 /50x.html; location = /50x.html { root html; }
# deny access to .htaccess files,if Apache's document root # concurs with nginx's one # location ~ /.ht { deny all; }
} 如果是apache配置rewrite,则参考这里http://www.52php.cn/jiaocheng/20.html (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |