环境准备
主机 |
IP |
web01 |
10.0.0.7 |
lb01 |
10.0.0.4 |
1)配置一个网站
[root@web01 /code]# vim /etc/nginx/conf.d/linux.jiechi.com.conf
server {
listen 80;
server_name linux.jiechi.com;
charset utf-8;
location / {
root /code/jc;
index index.html;
}
}
2)写一个网站页面
[root@web01 /code]# mkdir /code/jc
[root@web01 /code]# cat /code/jc/index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>我是title</title>
</head>
<body>
<article>
<header>
<h1>我是qiudao</h1>
<p>创建时间:<time pubdate="pubdate">2018/8/10</time></p>
</header>
<p>
<b>Aticle</b>第一次用h5写文章,好他*的紧张...
</p>
<footer>
<p><small>版权所有!</small></p>
</footer>
</article>
</body>
</html>
3)重启nginx访问
[root@web01 /code]# systemctl restart nginx
#配置hosts
10.0.0.7 linux.jiechi.com
4)配置劫持网站的网站
[root@lb01 ~]# vim /etc/nginx/conf.d/linux.jiechi.com.conf
server {
listen 80;
server_name linux.jiechi.com;
charset utf-8;
location / {
#劫持
proxy_pass http://10.0.0.7;
include proxy_params;
#篡改
sub_filter '<title>我是title</title>' '<title>我不是个东西</title>';
sub_filter '<b>qiudao</b>第一次用h5写文章,好他*的紧张...' '<img src="https://blog.driverzeng.com/zenglaoshi/xingganheguan.gif">';
}
}
5)配置hosts访问
[root@lb01 /code]# systemctl restart nginx
#配置hosts
#10.0.0.7 linux.jiechi.com
10.0.0.4 linux.jiechi.com