How can i get ip and port under forward proxy

Maxim Dounin mdounin at mdounin.ru
Wed Jun 5 12:18:15 UTC 2013


Hello!

On Wed, Jun 05, 2013 at 06:26:25AM -0400, honwel wrote:

> 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:

[...]

> 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. 

You may want to show your code if you want us to help.

Note well: upstream connection socket's file descriptor is 
available via u->peer.connection->fd after a successful
ngx_event_connect_peer() call in ngx_http_upstream_connect().  At 
this point, local sockaddr of the socket should be also valid as 
connect() was already called.

-- 
Maxim Dounin
http://nginx.org/en/donation.html



More information about the nginx mailing list