-bash-4.1# ip add | grep inet
    inet 172.17.0.7/16 scope global eth0
    inet6 fe80::42:acff:fe11:7/64 scope link 
    inet 127.0.0.1/8 scope host lo
    inet6 ::1/128 scope host 
    inet 192.168.32.154/24 brd 192.168.32.255 scope global eth1

192.168.32.154 配置反向代理:
     location /api {
                            proxy_pass    http://120.55.118.6:3000;
                            proxy_redirect default ;
                 }

120.55.118.6:3000 对应的接口:




 get '/api/ipsearch' => sub {
 my $c = shift;
  my  $ip=$c->param('ip');
  if ($ip){
use LWP::UserAgent;
my  $ua = LWP::UserAgent->new;

 my $host = "http://ip.taobao.com/service/getIpInfo.php?ip=$ip";
my $request = HTTP::Request->new(GET=>"$host");
my $response = $ua->request($request);
my  $content= $response->decoded_content;
 $content =~ s/\\u([0-9a-fA-F]{4})/pack("U",,hex($1))/eg;  
  $content=encode(utf8,$content);
  $json_out       = decode_json($content);
 
 $c->render(json =>  $json_out->{data} );
				   };
				    };




http://192.168.32.154:8001/api/ipsearch?ip=202.101.172.35

 

对比haproxy 的反向代理:

        acl             api_req                 path_beg                -i                      /api
        use_backend     appserver_8082          if                      api_req


backend appserver_8082
        mode 		http
        balance 	roundrobin
       #option httpchk HEAD /api  HTTP/1.0
        server  	apphost11_8082 		10.171.2xx.55:8082  	check inter 2000 fall 3