Open-source program nginx rewrite rules/CI/yii/CakePHP/Symfony/wordpress/Drupal

Source: Internet
Author: User
Tags fpm ini php framework rar zip codeigniter drupal yii

CI nginx rewrite rules

Server {
Listen 80;
Server_name ttlsa.com www.ttlsa.com;
Root/data/site/www.ttlsa.com;
Index. php;
Error_log log/error. log;
# Set expiration of assets to MAX for caching
Location ~ *. (Ico | css | js | gif | jpe? G | png )(? [0-9] + )? $ {
Expires max;
Log_not_found off;
 }
# Main codeigniter rewrite rule
Location /{
Try_files $ uri // index. php;
 }
# Php parsing
Location ~ . Php $ {
Root/data/site/ttlsa.com /;
Try_files $ uri = 404;
Fastcgi_pass unix:/tmp/php5-fpm.sock; # Change to the corresponding FastCGI
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Include fastcgi_params;
Fastcgi_buffer_size 128 k;
Fastcgi_buffers 256 4 k;
Fastcgi_busy_buffers_size 256 k;
Fastcgi_temp_file_write_size 256 k;
 }
}


Modify the CI (CodeIgniter) configuration file config. php
$ Config ['base _ url'] = "http://www.ttlsa.com /";
$ Config ['index _ page'] = "";
$ Config ['uri _ protocol'] = "REQUEST_URI ";

Yii nginx rewrite rules

Server {
Set $ host_path "/data/site/www.ttlsa.com ";
Access_log/data/logs/nginx/www.ttlsa.com _ access. log main;
Server_name ttlsa.com www.ttlsa.com;
Root $ host_path/htdocs;
Set $ yii_bootstrap "index. php ";
# Define charset
Charset UTF-8;
Location /{
Index index.html $ yii_bootstrap;
Try_files $ uri // $ yii_bootstrap? $ Args;
 }
# Deny access to protected directories
Location ~ ^/(Protected | framework | themes/w +/views ){
Deny all;
 }
# Avoid processing of callto 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 callto 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 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 128 k;
Fastcgi_buffers 256 4 k;
Fastcgi_busy_buffers_size 256 k;
Fastcgi_temp_file_write_size 256 k;
 }
}

The nginx rewrite rules for CakePHP are as follows:

Server {
Listen 80;
Server_name www.ttlsa.com;
Root/data/site/www.ttlsa.com;
Index. php;
Access_log/data/logs/nginx/www.ttlsa.com _ accerss. log;
Error_log/data/logs/nginx/www.ttlsa.com _ error. log;
# Main cakephp rewrite rule
Location /{
Try_files $ uri // index. php? $ Uri & $ args;
 }
Location ~ . Php $ {
Root/data/site/www.ttlsa.com;
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 128 k;
Fastcgi_buffers 256 4 k;
Fastcgi_busy_buffers_size 256 k;
Fastcgi_temp_file_write_size 256 k;
 }
}

Restart nginx.

Symfony nginx rewrite rules

Symfony is a popular php framework in foreign countries. Currently, it is rarely used in China, but it will certainly get angry in China. The nginx rewrite rules are as follows:

Server {
Server_name ttlsa.com www.ttlsa.com;
Root/data/site/www.ttlsa.com;
Location /{
# Try to serve file directly, fallback to rewrite
Try_files $ uri @ rewriteapp;
 }
Location @ rewriteapp {
# Rewrite all to app. php
Rewrite ^ (. *) $/app. php/$1 last;
 }
Location ~ ^/(App | app_dev | config). php (/| $ ){
Fastcgi_pass unix:/var/run/php5-fpm.sock; # Change to your corresponding FastCGI
Fastcgi_split_path_info ^ (. +. php) (/. *) $;
Include fastcgi_params;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Fastcgi_param HTTPS off;
 }
Error_log/data/logs/nginx/www.ttlsa.com _ error. log;
 }

Wordpress nginx rewrite rules

Wordpress is currently the most popular blog system in the world, and ttlsa is also built by wordpress. The nginx rewrite rules are as follows:

Print?
Server {
Listen 80;
Server_name www.ttlsa.com ttlsa.com;
Access_log/data/logs/nginx/www.ttlsa.com. access. log main;
 
Index index.html index. php;
Root/data/site/www.ttlsa.com;
Location /{
Try_files $ uri // index. php? $ Args;
Add_header Pragma "public ";
Expires 12 h;
}
 
Rewrite/wp-admin $ scheme: // $ host $ uri/permanent;
 
Location ~ * ^. + \. (Ogg | ogv | svg | svgz | eot | otf | woff | mp4 | ttf | rss | atom | jpg | jpeg | gif | png | ico | zip | tgz | gz | rar | bz2 | doc | xls | exe | ppt | tar | mid | midi | wav | bmp | rtf) $ {
Access_log off;
Log_not_found off;
Expires max;
}
 
 
Location ~ \. Php $ {
Try_files $ uri = 404;
 
Fastcgi_split_path_info ^ (. + \. php) (/. +) $;
# NOTE: You shoshould have "cgi. fix_pathinfo = 0;" in php. ini
 
Include fastcgi_params;
Fastcgi_index index. php;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
# Fastcgi_intercept_errors on;
Fastcgi_pass 127.0.0.1: 9000;
}
 
Location ~ . * \. (Gif | jpg | jpeg | png | bmp | swf) $
{
Expires 24 h;
Access_log off;
}
 
Location ~ . * \. (Js | css) $
{
Expires 24 h;
Access_log off;
}

Drupal nginx rewrite rules

Drupal nginx rewrite rules are as follows:

 
Server {
...
Location /{
# This is cool because no php is touched for static content
Try_files $ uri @ rewrite;
 }
Location @ rewrite {
# Some modules enforce no slash (/) at the end of the URL
# Else this rewrite block wouldn't be needed (GlobalRedirect)
Rewrite ^/(. *) $/index. php? Q = $1;
 }
Location ~ \. Php $ {
Fastcgi_split_path_info ^ (. + \. php) (/. +) $;
# NOTE: You shoshould have "cgi. fix_pathinfo = 0;" in php. ini
Include fastcgi_params;
Fastcgi_param SCRIPT_FILENAME $ document_root $ fastcgi_script_name;
Fastcgi_intercept_errors on;
Fastcgi_pass unix:/tmp/phpfpm. sock;
 }
...
 }


Note: After rewrite rules are configured, remember to 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.