nginx正向代理反向代理

正向代理:代理对象是客服端
反向代理:代理对象是服务端
区别所代理的对象不一样

#配置语法
Syntax: proxy_pass URL;
Default:-
ContextLlocation,if in location,limit_except
#配置
#192.168.0.250 (代理服务器)

resolver 8.8.8.8;
location / {
    #default_type text/html;
    #return 200 http_host:$http_host<br>request_uri:$request_uri;
    proxy_set_header X-Forwarded-For 250.cn;
    proxy_pass http://$http_host$request_uri;
}

#192.168.0.251
location / {
    default_type text/html;
    if ($http_x_forwarded_for != "250.cn" ){
        return 200 http_x_forwarded_for:$http_x_forwarded_for;
     }
    index  index.html index.htm;
    autoindex on;
    autoindex_exact_size off;
    autoindex_localtime on;
    }

本地访问
http://251.cn/
客户端设置250的代理(chrome可通过SwitchySharp)
才能真正访问到

250.cn
location /proxy{
            proxy_pass http://251.cn;
        }

http://250.cn/proxy/a  ->http://251.cn/proxy/a


proxy_pass http://251.cn/;
http://250.cn/proxy/news  -> http://251.cn//news

proxy_pass http://251.cn/proxy;
http://250.cn/proxy/news    ->http://251.cn/proxy/news

proxy_pass http://251.cn/proxy/
http://250.cn/proxy/news  ->http://251.cn/proxy//news
http://250.cn/proxynews    ->http://251.cn/proxy/news

proxy_pass 所在的location 后不能有正则表达式 
 "proxy_pass" cannot have URI part in location given by regular expression, 
or inside named location, or inside "if" statement, or inside "limit_except" block in /usr/local/nginx/conf/nginx.conf:88 所在的块不能有rewrite

待续.....