nginx代理

正向代理:代理對象是客服端
反向代理:代理對象是服務端
區別所代理的對象不同html

#配置語法
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)
才能真正訪問到nginx

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

待續.....正則表達式

相關文章
相關標籤/搜索