Setup redirection using Proxypass, proxyreversepass on apache

Date Posted: 24-08-2017

There are scenarios like we would like to forward the request to different domain or different port. However, the URL on the browser should remain the same. In this post, we will explain on how to setup redirection using proxypass.

Assumption:

Let’s assume that we want to redirect all the request to be forwarded to port 8000. If the port number or URL is different, modify the proxy accordingly on below section

Prerequisites:

  1. Ubuntu or centos Server
  2. Apache 2.4 or apache 2.2
  3. Mod_proxy module. We can verify whether mod_proxy is installed or not using the below command

apachectl -M

Implementation:

Identify the domain virtualhost configuration. The default location on ubuntu is /etc/apache2/sites-enabled/000-default.conf. If the domain has different documentroot then you would need to edit corresponding virtualhost.

vi /etc/apache2/sites-enabled/000-default.conf

Add the below lines between <virtualhost> and </virtualhost> line.

ProxyPass / http://localhost:8000/
ProxyPassReverse / http://localhost:8000/

Where,

localhost is the IP address. If its a different server, we can mention the IP address

Check for syntax error.

apachectl -t

Restart the apache service

service apache2 restart

 

Leave a Reply