Using mod proxy to pass requests to local servers transparently

From Notes_Wiki
Revision as of 08:16, 2 December 2012 by Saurabh (talk | contribs)

<yambe:breadcrumb>Apache web server configuration</yambe:breadcrumb>

Using mod proxy to pass requests to local servers transparently

We can use 'ProxyPass' and 'ReverseProxyPass' apache configuration directives to pass requests coming to virtual host or to given path at virtual host to another web server. For example if we have yaws web server listening on localhost:8888 then we can use following configuration to pass all requests sent to 'http://server/tools/' to to to http://localhost:8888/ internally.

    ProxyPass /tools/ http://127.0.0.1:8888/
    ProxyPassReverse /tools/ http://127.0.0.1:8888/

Please note that because requests are being forwarded local server will not get correct access logs and machine itself will appear as client in all requests. However apache server will get correct logs with correct client IPs for URLs http://server/tools/*

Note that we can pass the information of originating server using directive

    ProxyVia On

When we use this apache will put IP address of original client in 'X-Forwarded-For' HTTP request header while proxying request so that ProxyPass destination machine can make decision based on actual clients, and even log it.