Difference between revisions of "Using mod proxy to pass requests to local servers transparently"
m |
m |
||
Line 18: | Line 18: | ||
In case the port number and URL on server are different then few things may not work. For example: | |||
<pre> | <pre> | ||
<VirtualHost *:80> | <VirtualHost *:80> | ||
Line 32: | Line 32: | ||
</VirtualHost> | </VirtualHost> | ||
</pre> | </pre> | ||
creates issues with images and various links by appending an unnecessary /anusaaraka on most links. However if we use following configuration: | |||
<pre> | |||
<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> | |||
</pre> | |||
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</yambe:breadcrumb> | <yambe:breadcrumb self="Using mod proxy">Apache web server configuration</yambe:breadcrumb> |
Revision as of 09:56, 28 May 2015
<yambe:breadcrumb self="Using mod proxy">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</yambe:breadcrumb>