nginx 代理
nginx 代理
- cd /usr/local/nginx/conf/vhost
- vim proxy.conf //加入如下内容
server
{
listen 80;
server_name www.test02.com;
location ~ "zrlog*"
{
proxy_pass http://www.test.com/;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
}
//匹配到zrlog后使用代理 代理到 www.test.com
//需要在/etc/hosts设置 192.168.200.160 www.test.com
//去指向代理的IP,或者想负载均衡一样使用upstream设置访问ip
ngx_http_proxy_module
- proxy_pass
syntax: proxy_pass URL
context: location,if in location,limit_except
- proxy_pass http://test02.com/uri/;
客户请求的后面的将原样代理给服务器test02
example:
server_name www.test01.com
proxy_pass http://test02.com/uri/;
客户:www.test01.com/test01.html 将访问http://test02.com/test01.html
- proxy_pass http://test02.com/