Welcome! Log In Create A New Profile

Advanced

How can i get ip and port under forward proxy

June 05, 2013 06:26AM
Hi, there

I want to get ip and port under forward proxy use NGINX, a forward proxy sketch like this:

[Client ]-> [NGINX] -> [Internet]

so i want to get proxy's ip and port . i have try and made some modifications to the source code including ngx_http_upstream.c ngx_event_connect.c , there are some details: 1、add local_socket variable to get socket fd in ngx_event_connect_peer() 2、add local_sockaddr to get sockaddr structure in ngx_http_upstream_process_header(), because in this function the proxy had connected(connect() in ngx_event_connect_peer() is nonblocking) to the upstream(web, e.g. google.com) 3、add a $upstream_laddr variable in the ngx_http_upstream.c as ngx_http_upstream_addr_variable() function. 4、set log property like:

fragment
****************************************************************************** log property start
'$remote_addr:$remote_port ($upstream_laddr) [$time_local] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';
****************************************************************************** log property end

However, everthing does not work properly, the debug.log like this:

2013/06/05 16:35:50 [debug] 4978#0: *1 http upstream process header
2013/06/05 16:35:50 [debug] 4978#0: *1 http upstream connect socket: 12
2013/06/05 16:35:50 [debug] 4978#0: *1 http upstream connect sa_family: 21920
2013/06/05 16:35:50 [debug] 4978#0: *1 http upstream connect uri: / HTTP/1.1^M
Host
2013/06/05 16:35:50 [debug] 4978#0: *1 http upstream connect ip: 255.127.0.0:5067 note: Worng ip and Port
2013/06/05 16:35:50 [debug] 4978#0: *1 http proxy status 200 "200 OK"
.......................
2013/06/05 16:38:57 [debug] 4978#0: *14 http upstream connect sa_family: 29728 note: Worng sa_family type
2013/06/05 16:38:57 [debug] 4978#0: *14 http upstream connect uri: /static/channel/focustop/focustop/focustop_105e9cbe.js HTTP/1.1^M
Host
2013/06/05 16:38:57 [debug] 4978#0: *14 http upstream connect ip: 112.111.114.97:25965ÿ^? note:Worng IP and Port
2013/06/05 16:38:57 [debug] 4978#0: *14 http proxy status 304 "304 Not Modified"
.........................

2013/06/05 17:05:32 [debug] 4978#0: *62 http upstream connect socket: 20
2013/06/05 17:05:32 [debug] 4978#0: *62 http upstream connect sa_family: 2
2013/06/05 17:05:32 [debug] 4978#0: *62 http upstream connect uri: /images1/ch/09xwzx/h_1.gif HTTP/1.1^M
Host
2013/06/05 17:05:32 [debug] 4978#0: *62 http upstream connect ip: 192.168.1.163:49217Ëÿ^? note:Correct IP and Port
2013/06/05 17:05:32 [debug] 4978#0: *62 http proxy status 304 "304 Not Modified"

Does i have made mistake for code or worng understanding of NGINX event model. how can make this work correctly to get IP and Port.

Thanks in advance.
Subject Author Posted

How can i get ip and port under forward proxy

honwel June 05, 2013 06:26AM

Re: How can i get ip and port under forward proxy

Maxim Dounin June 05, 2013 08:20AM

Re: How can i get ip and port under forward proxy

honwel June 05, 2013 09:10PM

Re: How can i get ip and port under forward proxy

Maxim Dounin June 06, 2013 09:04AM

Re: How can i get ip and port under forward proxy

honwel June 06, 2013 09:29PM

Re: How can i get ip and port under forward proxy

Maxim Dounin June 06, 2013 10:06PM

Re: How can i get ip and port under forward proxy

honwel June 05, 2013 09:37PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 71
Record Number of Users: 6 on February 25, 2016
Record Number of Guests: 238 on March 17, 2016
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready