1.首先安装lnmp
2.升级Nginx至1.0.8版(我是cd /root后升级的)

[复制代码]    展开/关闭 下载 code.txt1
2
cd /root      //我是返回root目录里再进行操作的,我是为了方便查看
wget http://soft.vpser.net/lnmp/upgrade_nginx.sh;sh upgrade_nginx.sh

3.安装预备软件
1 yum -y --noplugins install wget zip
2 yum -y --noplugins install unzip
3 yum -y --noplugins install gcc
4 yum -y --noplugins install make
5 yum -y --noplugins install pcre-devel
6 yum -y --noplugins install openssl-devel
7 yum -y --noplugins install subversion

4.下载substitutions
svn checkout http://substitutions4nginx.googlecode.com/svn/trunk/ substitutions4nginx-read-only

5.编译
1 cd nginx-1.0.8
2 ./configure
3./configure --add-module=/root/substitutions4nginx-read-only
4make
5make install

6.编辑Nginx配置文件
vim /usr/local/nginx/conf/nginx.conf

从第53行的server到倒数第二行全部删掉(最后一行的”}”要留下哦亲)
然后添加(在最后的”}”上面添加哦亲)
1  server_name  www.xxx.com;
2l ocation / {
3 subs_filter ca-pub-9805743306566114  ca-pub-98057433063434;        //把google ad 的用户号 ca-pub-9805743306566114 改成你自己的,比如 ca-pub-98057433063434
4 subs_filter 6121088089    612108343455;      //把google ad 的广告号 6121088089  改成你自己的,比如 612108343455(太邪恶了)
5subs_filter www.hostloc.com www.xxx.com;
6subs_filter '全球主机交流论坛' '全球MJJ交流论坛' gi;
7 proxy_set_header referer http://www.hostloc.com;  //这一条解决验证码不显示的问题
8 proxy_pass   http://www.hostloc.com;
9 index  index.html index.htm;
10   }
11include vhost/*.conf;  //这个只需要在最后的"}"上面出现一次就可以了,添加其他规则的话无需重复添加这条

nginx.conf 要保存成 utf8格式才能替换中文字符
记住subs_filter 命令的格式,你想替换设么就随你了。
另外, 反向代理的个数是不限制的。只要你掌握了规则,一个网站下可以包含n多个网站的镜像。 一个nginx 上也可以跑 n多个网站。就看你自己怎么运用了。
别忘了吧logo地址替换成自己的

7.添加好后,先执行:
/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
则正常,否则按错误提示修改配置。
再执行
1 kill -HUP `cat /usr/local/nginx/logs/nginx.pid`
2 /usr/local/nginx/sbin/nginx

使配置生效。

Last modification:February 2nd, 2019 at 08:25 am
If you think my article is useful to you, please feel free to appreciate