1、获取网站IP地址
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
[root@plinuxos ~]
# yum install -y bind-utils ##安装dig命令
[root@plinuxos ~]
# dig baidu.com
; <<>> DiG 9.9.4-RedHat-9.9.4-50.el7_3.1 <<>> baidu.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR,
id
: 63640
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1
;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 4096
;; QUESTION SECTION:
;baidu.com. IN A
;; ANSWER SECTION:
baidu.com. 37 IN A 123.125.114.144
##地址1
baidu.com. 37 IN A 220.181.57.217
##地址2
baidu.com. 37 IN A 111.13.101.208
##地址3
;; Query
time
: 8 msec
;; SERVER: 114.114.114.114
#53(114.114.114.114)
;; WHEN: Tue Aug 15 21:55:50 CST 2017
;; MSG SIZE rcvd: 86
|
2、编辑配置文件
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
[root@plinuxos ~]
# vi /usr/local/nginx/conf/vhost/ld.conf
upstream baidu
{
ip_hash;
##算法
server 123.125.114.144:80;
server 220.181.57.217:80;
server 111.13.101.208:80;
}
server
{
listen 80;
server_name www.baidu.com;
##域名
location /
{
proxy_pass http:
//baidu
;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
|
3、检查与重载
1
2
3
4
|
[root@plinuxos ~]
# /usr/local/nginx/sbin/nginx -t
nginx: the configuration
file
/usr/local/nginx/conf/nginx
.conf syntax is ok
nginx: configuration
file
/usr/local/nginx/conf/nginx
.conf
test
is successful
[root@plinuxos ~]
# /usr/local/nginx/sbin/nginx -s reload
|
4、测试效果
1
2
3
4
|
[root@plinuxos ~]
# curl -x127.0.0.1:80 www.baidu.com
<html>
<meta http-equiv=
"refresh"
content=
"0;url=http://www.baidu.com/"
>
<
/html
>
|
本文转自Grodd51CTO博客,原文链接:http://blog.51cto.com/juispan/1956575
,如需转载请自行联系原作者