Nginx 反向代理 做其他网站的镜像

要点只有2个:

1. 反向代理
2. 关键词替换

下面就讲讲过程 (centos5/6-32bit/64bit已测试)

1. nginx + substitutions 安装
nginx 自带一个Substitution模块,
但该模块只能写一行,所以我们改用 substitutions

下面是安装一些预备软件

yum -y –noplugins install wget zip
yum -y –noplugins install unzip
yum -y –noplugins install gcc
yum -y –noplugins install make
yum -y –noplugins install pcre-devel
yum -y –noplugins install openssl-devel

下载软件

wget -c http://www.nginx.org/download/nginx-1.0.8.tar.gz                      //下载nginx
svn checkout http://substitutions4nginx.googlecode.com/svn/trunk/ substitutions4nginx-read-only          //下载substitutions

编译软件
tar zxf nginx-1.0.8.tar.gz
cd nginx-1.0.8.tar.gz
./configure ./configure –add-module=path/substitutions4nginx-read-only           //注意这里的path是相对应的真实路径

make
make install

此时,nginx应该安装在于 /usr/local/nginx 下面
配置 nginx.conf
server_name  www.你的域名.com;
location / {
subs_filter 1原内容  2新内容;
subs_filter 源内容   新内容;
proxy_pass   http://www.别人域名.com;
index  index.html index.php index.htm;
}
记住subs_filter 命令的格式,你想替换设么就随你了。
比如我把网站的网址www.1.com替换成了www.2.com

这种模式最好是修改nginx源代码 把301 move的head改为200 ok的返回
否则Google可能有关键词权重的问题….
还有就是正则表达式的写法 处理掉get和post的相关请求后缀

One thought on “Nginx 反向代理 做其他网站的镜像

  1. 有点感觉没讲玩的呀

发表回复

您的电子邮箱地址不会被公开。 必填项已用*标注