开源中国_开源程序nginx重写规则/CI/yii/CakePHP/Symfony/wordpress/Drupal

更新时间:2019-10-08    来源:Symfony    手机版     字体:

【www.bbyears.com--Symfony】

CI nginx重写规则

server {
 listen 80;
 server_name ttlsa.com www.ttlsa.com;
root /data/site/www.ttlsa.com;
 index 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 $uri/ /index.php;
 }
# php parsing
 location ~ .php$ {
 root /data/site/ttlsa.com/;
 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;
 }
}


修改CI(CodeIgniter )配置文件config.php
$config["base_url"] = "http://www.ttlsa.com/";
 $config["index_page"] = "";
 $config["uri_protocol"] = "REQUEST_URI";

yii nginx重写规则

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 $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;
 }
}

CakePHP nginx重写规则如下

server {
 listen 80;
 server_name www.ttlsa.com;
root /data/site/www.ttlsa.com;
 index 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 $uri/ /index.php?$uri&$args;
 }
location ~ .php$ {
 root /data/site/www.ttlsa.com;
 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即可

Symfony nginx重写规则

Symfony国外很流行的php框架,目前国内用的相对较少,但是一定会在国内火起来. nginx重写规则如下

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; # 改成你对应的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重写规则

wordpress目前是世界上最流行的博客系统,ttlsa也是由wordpress搭建而成,nginx重写规则如下:

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 $uri/ /index.php?$args;
        add_header Pragma "public";
        expires 12h;
}
 
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 should 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 24h;
        access_log off;
}
 
location ~ .*\.(js|css)$
{
        expires 24h;
        access_log off;
}

Drupal nginx重写规则

Drupal nginx重写规则如下:

 
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 should 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;
 }
...
 }


注:配置了重写规则后,要记得重启nginx哦。

本文来源:http://www.bbyears.com/jiaocheng/72041.html