Nginx配置PHP的Yii与CakePHP框架的rewrite规则示例
php  /  管理员 发布于 7年前   203
Yii的Nginx rewrite
如下为nginx yii的重写
server {set $host_path "/data/site/"; access_log /data/logs/nginx/_access.log main;server_name .net.cn ;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 ;root /data/site/; index index.php;access_log /data/logs/nginx/_accerss.log; error_log /data/logs/nginx/_error.log;# main cakephp rewrite rule location / { try_files $uri $uri/ /index.php?$uri&$args; }location ~ .php$ { root /data/site/; 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即可
122 在
学历:一种延缓就业设计,生活需求下的权衡之选中评论 工作几年后,报名考研了,到现在还没认真学习备考,迷茫中。作为一名北漂互联网打工人..123 在
Clash for Windows作者删库跑路了,github已404中评论 按理说只要你在国内,所有的流量进出都在监控范围内,不管你怎么隐藏也没用,想搞你分..原梓番博客 在
在Laravel框架中使用模型Model分表最简单的方法中评论 好久好久都没看友情链接申请了,今天刚看,已经添加。..博主 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 @1111老铁这个不行了,可以看看近期评论的其他文章..1111 在
佛跳墙vpn软件不会用?上不了网?佛跳墙vpn常见问题以及解决办法中评论 网站不能打开,博主百忙中能否发个APP下载链接,佛跳墙或极光..
Copyright·© 2019 侯体宗版权所有·
粤ICP备20027696号