WordPress与Drupal的Nginx配置rewrite重写规则示例
WordPress
wordpress依然是目前是世界上最流行的博客系统,越来越多由wordpress搭建而成的网站在使用nginx服务器软件,这里就来分享一下WordPress的nginx重写规则:
server{
listen80;
server_namewww.nhooo.comjb51.net;
access_log/data/logs/nginx/www.nhooo.com.access.logmain;
indexindex.htmlindex.php;
root/data/site/www.nhooo.com;
location/{
try_files$uri$uri//index.php?$args;
add_headerPragma"public";
expires12h;
}
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_logoff;
log_not_foundoff;
expiresmax;
}
location~\.php${
try_files$uri=404;
fastcgi_split_path_info^(.+\.php)(/.+)$;
#NOTE:Youshouldhave"cgi.fix_pathinfo=0;"inphp.ini
includefastcgi_params;
fastcgi_indexindex.php;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
#fastcgi_intercept_errorson;
fastcgi_pass127.0.0.1:9000;
}
location~.*\.(gif|jpg|jpeg|png|bmp|swf)$
{
expires24h;
access_logoff;
}
location~.*\.(js|css)$
{
expires24h;
access_logoff;
}
重启你的nginx即可
Drupalnginx重写规则
Drupal是使用PHP语言编写的开源内容管理框架,就是俗称的CMS,很多人在用Drupal搭建自己的博客,这里也来分享一下Drupal的nginx重写规则:
server{
...
location/{
#Thisiscoolbecausenophpistouchedforstaticcontent
try_files$uri@rewrite;
}
location@rewrite{
#Somemodulesenforcenoslash(/)attheendoftheURL
#Elsethisrewriteblockwouldn'tbeneeded(GlobalRedirect)
rewrite^/(.*)$/index.php?q=$1;
}
location~\.php${
fastcgi_split_path_info^(.+\.php)(/.+)$;
#NOTE:Youshouldhave"cgi.fix_pathinfo=0;"inphp.ini
includefastcgi_params;
fastcgi_paramSCRIPT_FILENAME$document_root$fastcgi_script_name;
fastcgi_intercept_errorson;
fastcgi_passunix:/tmp/phpfpm.sock;
}
...
}
重启nginx