先安装一些预备软件
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
yum -y --noplugins install subversion
下载Nginx
wget -c http://www.nginx.org/download/nginx-1.0.8.tar.gz
下载substitutions
svn checkout http://substitutions4nginx.googlecode.com/svn/trunk/ substitutions4nginx-read-only
编译软件
tar zxf nginx-1.0.8.tar.gz
cd nginx-1.0.8
./configure
./configure --add-module=/root/substitutions4nginx-read-only //注意这里的path是相对应的真实路径
make
make install
此时,nginx配置文件应该安装在于 /usr/local/nginx/conf 下面新建配置文件
vim www.server110.com.conf
server {
listen 80;
server_name www.server110.com; #绑定的域名
access_log off; #关闭日志
location / {
subs_filter 'www.baidu.com' 'www.server110.com' gi;#替换链接
subs_filter '百度' '度娘' gi;#替换文本
proxy_set_header referer http://www.baidu.com;#如果网站有验证码,可以解决验证码不显示问题
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host www.baidu.com; #定义主机头,如果目标站点绑定的域名个server_name项的吻合则使用$host
proxy_pass http://www.baidu.com; #指定目标,建议使用IP或者nginx自定义池
proxy_set_header Accept-Encoding ""; #清除编码
}
}
(记住subs_filter 命令的格式,你想替换设么就随你了。)编辑nginx.conf,把server部分全部去掉,改为
include www.server110.com.conf;
nginx.conf全部文本:
#user nobody;
worker_processes 1;
#error_log logs/error.log;
#error_log logs/error.log notice;
#error_log logs/error.log info;
#pid logs/nginx.pid;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
#log_format main '$remote_addr - $remote_user [$time_local] "$request" '
# '$status $body_bytes_sent "$http_referer" '
# '"$http_user_agent" "$http_x_forwarded_for"';
#access_log logs/access.log main;
sendfile on;
#tcp_nopush on;
#keepalive_timeout 0;
keepalive_timeout 65;
#gzip on;
include www.server110.com.conf;
}
保存之后由于需要改为utf-8编码,所以需要执行
sed -i "s/^xefxbbxbf//" nginx.conf
sed -i "s/^xefxbbxbf//" www.server110.com.conf
测试nginx执行:
/usr/local/nginx/sbin/nginx -t
检查配置是否正常,如果显示:
the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok
configuration file /usr/local/nginx/conf/nginx.conf test is successful
则正常,否则按错误提示修改配置。再执行
kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
/usr/local/nginx/sbin/nginx
使配置生效另外, 反向代理的个数是不限制的。只要你掌握了规则,一个网站下可以包含n多个网站的镜像。 一个
nginx 上也可以跑 n多个网站。就看你自己怎么运用了。
别忘了吧logo地址替换成自己的
目前唯一的已知缺陷是登陆后会自动跳转回原网址,以后解决了再更新。