Nginx Configure the Rewrite rule example for the Yii and cake framework of PHP _nginx

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.