The Nginx rewrite of Yii
The following is the rewriting of Nginx Yii
server {set $host _path "/data/site/www.jb51.net";
Access_log/data/logs/nginx/www.jb51.net_access.log main;
server_name jb51.net www.jb51.net;
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;
# change to your corresponding fastcgi include fastcgi_params;
Fastcgi_param script_filename $document _ROOT$FSN; #PATH_INFO and path_translated can is 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;
}
}
Don't forget to restart Nginx when you are done with the configuration.
Cake 's Nginx rewrite rules
still simple and rough, directly on the code example, the Nginx rewrite rules are as follows
server {
listen;
server_name www.jb51.net;
root/data/site/www.jb51.net;
Index index.php;
Access_log/data/logs/nginx/www.jb51.net_accerss.log;
Error_log/data/logs/nginx/www.jb51.net_error.log;
# main cake Rewrite rule
location/{
try_files $uri $uri//index.php? $uri & $args;
}
Location ~. php$ {
root/data/site/www.jb51.net;
Try_files $uri =404;
Fastcgi_pass Unix:/tmp/php5-fpm.sock; # change to your corresponding 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;
}
}
Restart Nginx