niginx能实现代理功能。我们通过一个代理实现访问。但是国内访问不了google。现在通过代理实现本地访问google。前提是做代理的机器要能访问google。
1、编辑配置文件
[root@bogon ~]# cd /usr/local/nginx/conf/vhosts/
[root@bogon vhosts]# ls
111.conf default.conf test.conf
[root@bogon vhosts]# vim proxy.conf
server {
listen 80;
server_name www.baidu.com;
location / {
proxy_pass http://112.80.248.73/;
#proxy_set_header Host $host;
}
}
[root@bogon vhosts]# /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
2、测试:
通过代理百度。本机通过百度的代理指向,去访问。
多个ip也就是负载平衡。设置:
upstream caimz{
server 112.80.248.73:80;
server 112.80.248.74:80;
}
server {
listen 80;
server_name www.baidu.com;
location / {
proxy_pass http://caimz/;
#proxy_set_hearder Host $host;
}
}