Difference between revisions of "Using mod proxy to pass requests to local servers transparently"

From Notes_Wiki
m
m
Line 1: Line 1:
<yambe:breadcrumb self="Using mod proxy">Apache web server configuration</yambe:breadcrumb>
<yambe:breadcrumb self="Using mod proxy">Apache web server configuration|Apache web server configuration</yambe:breadcrumb>
=Using mod proxy to pass requests to local servers transparently=
=Using mod proxy to pass requests to local servers transparently=


Line 47: Line 47:




<yambe:breadcrumb self="Using mod proxy">Apache web server configuration</yambe:breadcrumb>
<yambe:breadcrumb self="Using mod proxy">Apache web server configuration|Apache web server configuration</yambe:breadcrumb>

Revision as of 17:24, 17 August 2018

<yambe:breadcrumb self="Using mod proxy">Apache web server configuration|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.


In case the port number and URL on server are different then few things may not work. For example:

<VirtualHost *:80>
ServerAdmin rekall@sbarjatiya.com
#DocumentRoot /var/www/html
ServerName anusaaraka.iiit.ac.in
ErrorLog logs/anusaaraka.iiit.ac.in-error_log
CustomLog logs/anusaaraka.iiit.ac.in-access_log combined
<Location />
ProxyPass http://anu.iiit.ac.in:8080/anusaaraka/
ProxyPassReverse http://anu.iiit.ac.in:8080/anusaaraka/
</Location>
</VirtualHost>

creates issues with images and various links by appending an unnecessary /anusaaraka on most links. However if we use following configuration:

<VirtualHost *:80>
ServerAdmin rekall@sbarjatiya.com
DocumentRoot /var/www/anusaaraka
ServerName anusaaraka.iiit.ac.in
ErrorLog logs/anusaaraka.iiit.ac.in-error_log
CustomLog logs/anusaaraka.iiit.ac.in-access_log combined
ProxyPass /anusaaraka/ http://anu.iiit.ac.in:8080/anusaaraka/
ProxyPassReverse /anusaaraka/ http://anu.iiit.ac.in:8080/anusaaraka/
</VirtualHost>

after creating a redirect from / to /anusaaraka/ using HTTP-META refresh used in /var/www/anusaaraka/index.html the pages open properly with all images and links working as expected.


<yambe:breadcrumb self="Using mod proxy">Apache web server configuration|Apache web server configuration</yambe:breadcrumb>