文件和目录不存在的时候重定向:
复制代码 代码如下:
if (!-e $request_filename) {
proxy_pass http://127.0.0.1;
}
域名跳转
复制代码 代码如下:
server
{
listen 80;
server_name jump.c1gstudio.com;
index index.html index.htm index.php;
root /opt/lampp/htdocs/www;
rewrite ^/ //www.iis7.com/;
access_log off;
}
多域名转向
复制代码 代码如下:
server_name www.c1gstudio.com www.c1gstudio.net;
index index.html index.htm index.php;
root /opt/lampp/htdocs;
if ($host ~ “c1gstudio/.net”) {
rewrite ^(.*) //www.iis7.com$1 permanent;
}
三级域名跳转
复制代码 代码如下:
if ($http_host ~* “^(.*)/.i/.c1gstudio/.com$”) {
rewrite ^(.*) //www.iis7.com$1;
break;
}
域名镜像
复制代码 代码如下:
server
{
listen 80;
server_name mirror.c1gstudio.com;
index index.html index.htm index.php;
root /opt/lampp/htdocs/www;
rewrite ^/(.*) //www.iis7.com/$1 last;
access_log off;
}
某个子目录作镜像
复制代码 代码如下:
location ^~ /php {
rewrite ^.+ //www.iis7.com/ last;
break;
}
discuz ucenter home (uchome) rewrite
复制代码 代码如下:
rewrite ^/(space|network)-(.+)/.html$ /$1.php?rewrite=$2 last;
rewrite ^/(space|network)/.html$ /$1.php last;
rewrite ^/([0-9]+)$ /space.php?uid=$1 last;
discuz 7 rewrite
rewrite ^(.*)/archiver/((fid|tid)-[/w/-]+/.html)$ $1/archiver/index.php?$2 last;
rewrite ^(.*)/forum-([0-9]+)-([0-9]+)/.html$ $1/forumdisplay.php?fid=$2&page=$3 last;
rewrite ^(.*)/thread-([0-9]+)-([0-9]+)-([0-9]+)/.html$ $1/viewthread.php?tid=$2&extra=page/%3D$4&page=$3 last;
rewrite ^(.*)/profile-(username|uid)-(.+)/.html$ $1/viewpro.php?$2=$3 last;
rewrite ^(.*)/space-(username|uid)-(.+)/.html$ $1/space.php?$2=$3 last;
rewrite ^(.*)/tag-(.+)/.html$ $1/tag.php?name=$2 last;
给discuz某版块单独配置域名
server_name bbs.jb51.net news.jb51.net;
location = / {
if ($http_host ~ news/.jb51.net$) {
rewrite ^.+ http://news.jb51.net/forum-831-1.html last;
break;
}
}
discuz ucenter 头像 rewrite 优化
location ^~ /ucenter {
location ~ .*/.php?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fcgi.conf;
}
location /ucenter/data/avatar {
log_not_found off;
access_log off;
location ~ /(.*)_big/.jpg$ {
error_page 404 /ucenter/images/noavatar_big.gif;
}
location ~ /(.*)_middle/.jpg$ {
error_page 404 /ucenter/images/noavatar_middle.gif;
}
location ~ /(.*)_small/.jpg$ {
error_page 404 /ucenter/images/noavatar_small.gif;
}
expires 300;
break;
}
}
jspace rewrite
location ~ .*/.php?$
{
#fastcgi_pass unix:/tmp/php-cgi.sock;