Nginx can implement the function of the agent, we have a demand, now the domestic has put Google to prohibit, the United States can visit, Hong Kong can visit, then we can now do an agent, can achieve through a proxy to visit Baidu, Google and so any one site, We come to learn how the agent to configure: (to Agent Baidu for example)
To first know Baidu's IP:
[[email protected] ~]# Ping www.baidu.com
PING www.a.shifen.com (180.97.33.108) bytes of data.
Bytes from 180.97.33.108:icmp_seq=1 ttl=55 time=19.3 ms
Bytes from 180.97.33.108:icmp_seq=2 ttl=55 time=18.9 ms
Bytes from 180.97.33.108:icmp_seq=3 ttl=55 time=18.0 ms
To write the agent configuration file:
[Email protected] ~]# vim/usr/local/nginx/conf/vhosts/proxy.conf
Server
{
Listen 80;
server_name www.baidu.com;
Location/{
Proxy_pass http://180.97.33.108/;
Proxy_set_header HOST $host;
}
}
Check and Reload
[Email protected] ~]#/usr/local/nginx/sbin/nginx-t
[Email protected] ~]#/usr/local/nginx/sbin/nginx-s Reload
The test put Baidu's IP point to the machine, to visit Baidu:
[Email protected] ~]# curl-x127.0.0.1:80 www.baidu.com
Displays normal access.
This is the Nginx proxy.
We can also specify more than one machine, that is, the specified IP (180.97.33.108) can be multiple, in this case, can achieve "load balancing", how to configure multiple machine access Baidu?
Let's first look at Baidu where he resolved
To install a command first:
[email protected] ~]# Yum install bind*
(The dig command has the effect of "detecting which IP a domain name resolves to")
[Email protected] ~]# dig www.baidu.com
180.97.33.108
180.97.33.107
(two IPs found)
We want these two IPs we can go to proxy, can go to access, so to configure proxy files:
[Email protected] ~]# vim/usr/local/nginx/conf/vhosts/proxy.conf
Upstream lnmplinux { # Green Word section for "Custom" name
Server 180.97.33.108:80;
Server 180.97.33.107:80;
}
Server
{
Listen 80;
server_name www.baidu.com;
Location/{
Proxy_pass http://lnmplinux/; # This is the same as the "custom" name in the first sentence
Proxy_set_header HOST $host; # This is a "load balancer" to configure multiple machines.
}
}
Check, Reload
[Email protected] ~]#/usr/local/nginx/sbin/nginx-t
[Email protected] ~]#/usr/local/nginx/sbin/nginx-s Reload
To visit Baidu:
[Email protected] ~]# curl-x127.0.0.1:80 www.baidu.com
Success!
This section organizes:
[Email protected] ~]# vim/usr/local/nginx/conf/vhosts/proxy.conf
Upstream lnmplinux{
Server 180.97.33.108:80;
Server 180.97.33.107:80;
}
Server
{
Listen 80;
server_name www.baidu.com;
Location/{
Proxy_pass http://lnmplinux/;
Proxy_set_header HOST $host;
}
}
At this point, LNMP's study is over.
Lnmp--nginx Agent Detailed