{{ v.name }}
{{ v.cls }}类
{{ v.price }} ¥{{ v.price }}
yii框架是一个非常好用的php框架,开发快,上手容易,自推出以来广受好评,对于基本的yii框架开发来说,不需要特殊配置,但是对于一些高级功能,就需要对你的服务器进行一些设置了。
我所用到的服务器是ubuntu16.04下的nginx,所以这里就针对yii框架的nginx做一个小小的总结。
需要满足的特性
1、yii框架的url重写规则(此规则需要nginx0.8.6版本以上支持)2、对于.svn、.git等版本控制文件的忽略3、一些不应该直接访问的文件夹(例如framework、protected等)的禁止直接访问4、静态资源的缓存优化
配置文件
配置文件目录:
/etc/nginx/sites-available
复制一个该文件夹下的default到该目录下并重命名为www.example.com,作为虚拟域名的配置文件,复制并重命名命令如下:
sudocp/etc/nginx/sites-available/default/etc/nginx/sites-available/www.example.com
然后使用文字编辑器打开:
sudogedit/etc/nginx/sites-available/www.example.com
将原有内容清除并将如下内容复制到该文件中
server{#监听端口listen80;listen[::]:80;#字符集设置charsetutf-8;#项目根目录设置root/var/www/html/example.com/;#默认起始页设置indexindex.htmlindex.htmindex.nginx-debian.htmlindex.php;#域名设置server_namewww.example.com;#关闭不必要的日志location=/favicon.ico{log_not_foundoff;access_logoff;}#设置以下目录不能直接被访问location~^/(protected|framework|themes/w+/views){denyall;log_not_foundoff;access_logoff;}#设置url重写location/{#firstattempttoserverequestasfile,then#asdirectory,thenfallbacktodisplayinga404.try_files$uri$uri//index.php?$args;}#设置php解释器#passthephpscriptstofastcgiserverlisteningon127.0.0.1:9000#location~.php${includesnippets/fastcgi-php.conf;#withphp5.6-cgialone:#fastcgi_pass127.0.0.1:9000;#withphp5.6-fpm:fastcgi_passunix:/run/php/php5.6-fpm.sock;#fastcgi_indexindex.php;fastcgi_paramhttpson;includefastcgi.conf;if(!-f$request_filename){rewrite(.*)/index.php;}}#设置静态资源缓存优化location~*.(js|css|png|jpg|jpeg|gif|ico)${expiresmax;log_not_foundon;}#设置版本控制文件忽略#preventnginxfromservingdotfiles(.htaccess,.svn,.git,etc.)location~/.{denyall;access_logoff;log_not_foundoff;}}
最后,使用命令:
sudoln-s/etc/nginx/sites-available/www.example.com/etc/nginx/sites-enabled/www.example.com
创建一个软连接到sites-enabled下,然后,编辑hosts文件:
sudogedit/etc/hosts
在最后一行添加:
127.0.0.1www.example.com
就完成了配置
sites-available与sites-enabled之间的关系