首页 > 代码库 > Nginx 代理设置
Nginx 代理设置
假设需求访问谷歌
[root@LNMP vhosts]#vim /usr/local/nginx/conf/vhosts/proxy.conf
server {
listen 80;
server_name www.baidu.com;
location / {
proxy_pass http://180.97.33.107/; #百度的IP
#proxy_set_header Host $host;
}
}
--------------------------
访问测试
-----------------------------------------------------------------
nginx 实验负载均衡:用dig 命令查出百度的另一个IP
[root@LNMP vhosts]#vim /usr/local/nginx/conf/vhosts/proxy.conf
upstream baidu{
server 180.97.33.108:80;
server 180.97.33.107;
}
server {
listen 80;
server_name www.baidu.com;
location / {
proxy_pass http://baidu/;
proxy_set_header Host $host; # 这行要打不开,不然访问的时候会报 502
#proxy_set_header X-Real-IP $remote_addr;
}
}
-------------------------------------
本文出自 “CBO#Boy_Linux之路” 博客,请务必保留此出处http://20151213start.blog.51cto.com/9472657/1879551
Nginx 代理设置