参考资料
[1]. 跟老男孩学Linux运维:Web集群实战,老男孩
安装过程
Nginx rewrite 301 跳转
server{
listen 80;
server_name www.etiantian.org etiantian.org;
rewrite ^/(.*) http://www.baidu.com/$1 permanent;
location / {
root html/www;
index index.html index.htm;
}
## gzip buffer=32k flush=5s; 是高并发场景下
# access_log logs/access_www.log main;
}
实现不同域名的跳转-1
实现访问http://blog.etiantian.org时跳转到
http://www.etiantian.org/blog/oldboy.html
[root@www ~]# vim /application/nginx/conf/extra/blog.conf
## 编辑内容如下
server{
listen 80;
server_name blog.etiantian.org;
location / {
root html/blog;
index index.html index.htm;
}
access_log logs/access_bbs.log main gzip buffer=32k flush=5s;
if ( $http_host ~* "^(.*)\.etiantian\.org$"){
set $domain $1;
rewrite ^(.*) http://www.etiantian.org/$domain/oldboy.html break;
}
}
[root@www ~]# vim /application/nginx/html/www/blog/oldboy.html
添加任意内容
111
[root@www ~]# /application/nginx/sbin/nginx -t
[root@www ~]# /application/nginx/sbin/nginx -s reload
实现不同域名的跳转-2
实现访问http://www.etiantian.org/bbs时跳转到http://bbs.etiantian.org
[root@www ~]# vim /application/nginx/conf/extra/www.conf
## 编辑内容如下
server{
listen 80;
server_name www.etiantian.org etiantian.org;
location / {
root html/www;
index index.html index.htm;
}
access_log logs/access_www.log main gzip buffer=32k flush=5s;
rewrite ^(.*?)/bbs/ http://bbs.etiantian.org break;
}
[root@www ~]# vim /application/nginx/conf/extra/bbs.conf
## 编辑内容如下
server{
listen 80;
server_name bbs.etiantian.org;
location / {
root html/bbs;
index index.html index.htm;
}
access_log logs/access_bbs.log main gzip buffer=32k flush=5s;
}