发布于 2016-02-04 06:03:54 | 179 次阅读 | 评论: 0 | 来源: 网友投递

这里有新鲜出炉的YII 2.0教程,程序狗速度看过来!

Yii高性能PHP框架

Yii Framework是一个基于组件、用于开发大型 Web 应用的高性能 PHP 框架。Yii提供了今日Web 2.0应用开发所需要的几乎一切功能。Yii是最有效率的PHP框架之一。Yii是创始人薛强的心血结晶,于2008年1月1日开始开发。


这篇文章主要介绍了Nginx配置PHP的Yii与CakePHP框架的rewrite规则示例,是这两款高人气框架使用Nginx的关键配置点,需要的朋友可以参考下

Yii的Nginx rewrite

如下为nginx yii的重写


server {
set $host_path "/data/site/www.phperz.com";
 access_log /data/logs/nginx/www.phperz.com_access.log main;
server_name phperz.com www.phperz.com;
root $host_path/htdocs;
 set $yii_bootstrap "index.php";
# define charset
 charset utf-8;
location / {
 index index.html $yii_bootstrap;
 try_files $uri $uri/ /$yii_bootstrap?$args;
 }
# deny access to protected directories
 location ~ ^/(protected|framework|themes/w+/views) {
 deny all;
 }
#avoid processing of calls to unexisting static files by yii
 location ~ .(js|css|png|jpg|gif|swf|ico|pdf|mov|fla|zip|rar)$ {
 try_files $uri =404;
 }
# prevent nginx from serving dotfiles (.htaccess, .svn, .git, etc.)
 location ~ /. {
 deny all;
 access_log off;
 log_not_found off;
 }
# php-fpm configuration using socket
 location ~ .php {
 fastcgi_split_path_info ^(.+.php)(.*)$;
#yii catches the calls to unexising PHP files
 set $fsn /$yii_bootstrap;
 if (-f $document_root$fastcgi_script_name){
 set $fsn $fastcgi_script_name;
 }
fastcgi_pass unix:/tmp/php5-fpm.sock; # 改成你对应的FastCGI
 include fastcgi_params;
 fastcgi_param SCRIPT_FILENAME $document_root$fsn;
#PATH_INFO and PATH_TRANSLATED can be omitted, but RFC 3875 specifies them for CGI
 fastcgi_param PATH_INFO $fastcgi_path_info;
 fastcgi_param PATH_TRANSLATED $document_root$fsn;
## Tweak fastcgi buffers, just in case.
 fastcgi_buffer_size 128k;
 fastcgi_buffers 256 4k;
 fastcgi_busy_buffers_size 256k;
 fastcgi_temp_file_write_size 256k;
 }
}

配置完了别忘了重启Nginx。


CakePHP的Nginx重写规则
依然简单粗暴,直接上代码例子,nginx重写规则如下


server {
 listen 80;
 server_name www.phperz.com;
root /data/site/www.phperz.com;
 index index.php;
access_log /data/logs/nginx/www.phperz.com_accerss.log;
 error_log /data/logs/nginx/www.phperz.com_error.log;
# main cakephp rewrite rule
 location / {
 try_files $uri $uri/ /index.php?$uri&$args;
 }
location ~ .php$ {
 root /data/site/www.phperz.com;
 try_files $uri =404;
 fastcgi_pass unix:/tmp/php5-fpm.sock; # 改成你对应的FastCGI
 fastcgi_index index.php;
 fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
 include fastcgi_params;
 fastcgi_buffer_size 128k;
 fastcgi_buffers 256 4k;
 fastcgi_busy_buffers_size 256k;
 fastcgi_temp_file_write_size 256k;
 }
}

重启nginx即可



最新网友评论  共有(0)条评论 发布评论 返回顶部

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务