Apache as a Proxy/Reverse Proxy using mod proxy http

From Labrats.us
Jump to navigationJump to search

Install and setup CentOS 7 server as detailed int eh below article:

New CentOS 7 Server Setup Commands

Install apache / httpd

# yum install httpd
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.dal10.us.leaseweb.net
 * extras: mirror.dal10.us.leaseweb.net
 * updates: repo1.dal.innoscale.net
base                                                        | 3.6 kB  00:00:00     
epel                                                        | 4.7 kB  00:00:00     
extras                                                      | 2.9 kB  00:00:00     
updates                                                     | 2.9 kB  00:00:00     
(1/3): epel/x86_64/group_gz                                 |  95 kB  00:00:00     
(2/3): epel/x86_64/updateinfo                               | 1.0 MB  00:00:00     
(3/3): epel/x86_64/primary_db                               | 6.9 MB  00:00:00     
Resolving Dependencies
--> Running transaction check
---> Package httpd.x86_64 0:2.4.6-93.el7.centos will be installed
--> Processing Dependency: httpd-tools = 2.4.6-93.el7.centos for package: httpd-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: /etc/mime.types for package: httpd-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: libaprutil-1.so.0()(64bit) for package: httpd-2.4.6-93.el7.centos.x86_64
--> Processing Dependency: libapr-1.so.0()(64bit) for package: httpd-2.4.6-93.el7.centos.x86_64
--> Running transaction check
---> Package apr.x86_64 0:1.4.8-5.el7 will be installed
---> Package apr-util.x86_64 0:1.5.2-6.el7 will be installed
---> Package httpd-tools.x86_64 0:2.4.6-93.el7.centos will be installed
---> Package mailcap.noarch 0:2.1.41-2.el7 will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
 Package             Arch           Version                     Repository    Size
===================================================================================
Installing:
 httpd               x86_64         2.4.6-93.el7.centos         base         2.7 M
Installing for dependencies:
 apr                 x86_64         1.4.8-5.el7                 base         103 k
 apr-util            x86_64         1.5.2-6.el7                 base          92 k
 httpd-tools         x86_64         2.4.6-93.el7.centos         base          92 k
 mailcap             noarch         2.1.41-2.el7                base          31 k

Transaction Summary
===================================================================================
Install  1 Package (+4 Dependent packages)

Total download size: 3.0 M
Installed size: 10 M
Is this ok [y/d/N]: y
Downloading packages:
(1/5): apr-1.4.8-5.el7.x86_64.rpm                           | 103 kB  00:00:00     
(2/5): apr-util-1.5.2-6.el7.x86_64.rpm                      |  92 kB  00:00:00     
(3/5): httpd-tools-2.4.6-93.el7.centos.x86_64.rpm           |  92 kB  00:00:00     
(4/5): httpd-2.4.6-93.el7.centos.x86_64.rpm                 | 2.7 MB  00:00:00     
(5/5): mailcap-2.1.41-2.el7.noarch.rpm                      |  31 kB  00:00:00     
-----------------------------------------------------------------------------------
Total                                                 6.9 MB/s | 3.0 MB  00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : apr-1.4.8-5.el7.x86_64                                          1/5 
  Installing : apr-util-1.5.2-6.el7.x86_64                                     2/5 
  Installing : httpd-tools-2.4.6-93.el7.centos.x86_64                          3/5 
  Installing : mailcap-2.1.41-2.el7.noarch                                     4/5 
  Installing : httpd-2.4.6-93.el7.centos.x86_64                                5/5 
  Verifying  : apr-1.4.8-5.el7.x86_64                                          1/5 
  Verifying  : httpd-tools-2.4.6-93.el7.centos.x86_64                          2/5 
  Verifying  : mailcap-2.1.41-2.el7.noarch                                     3/5 
  Verifying  : httpd-2.4.6-93.el7.centos.x86_64                                4/5 
  Verifying  : apr-util-1.5.2-6.el7.x86_64                                     5/5 

Installed:
  httpd.x86_64 0:2.4.6-93.el7.centos                                               

Dependency Installed:
  apr.x86_64 0:1.4.8-5.el7                      apr-util.x86_64 0:1.5.2-6.el7     
  httpd-tools.x86_64 0:2.4.6-93.el7.centos      mailcap.noarch 0:2.1.41-2.el7     

Complete!

Install mod_proxy_html

# yum install mod_proxy_html
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirror.dal10.us.leaseweb.net
 * extras: mirror.dal10.us.leaseweb.net
 * updates: repo1.dal.innoscale.net
Resolving Dependencies
--> Running transaction check
---> Package mod_proxy_html.x86_64 1:2.4.6-93.el7.centos will be installed
--> Finished Dependency Resolution

Dependencies Resolved

===================================================================================
 Package              Arch         Version                        Repository  Size
===================================================================================
Installing:
 mod_proxy_html       x86_64       1:2.4.6-93.el7.centos          base        51 k

Transaction Summary
===================================================================================
Install  1 Package

Total download size: 51 k
Installed size: 58 k
Is this ok [y/d/N]: y
Downloading packages:
mod_proxy_html-2.4.6-93.el7.centos.x86_64.rpm               |  51 kB  00:00:00     
Running transaction check
Running transaction test
Transaction test succeeded
Running transaction
  Installing : 1:mod_proxy_html-2.4.6-93.el7.centos.x86_64                     1/1 
  Verifying  : 1:mod_proxy_html-2.4.6-93.el7.centos.x86_64                     1/1 

Installed:
  mod_proxy_html.x86_64 1:2.4.6-93.el7.centos                                      

Complete!

Update ServerName setting in /etc/httpd/conf/httpd.conf

ServerName den1-webmail-proxy.risebroadband.com:80

Add virtual hosts to /etc/httpd/conf.d/virtualhosts.conf

<VirtualHost *:80>
  ServerName mail2.compassnet.com
  ProxyRequests On
  ProxyPass / http://mail.compassnet.com/
  ProxyPassReverse / http://mail.compassnet.com/
  ProxyPassReverseCookieDomain  "mail.compassnet.com"  "mail2.compassnet.com"
</VirtualHost>

<VirtualHost *:80>
  ServerName mail2.reinfo.org
  ProxyRequests On
  ProxyPass / http://mail.reinfo.org/
  ProxyPassReverse / http://mail.reinfo.org/
  ProxyPassReverseCookieDomain  "mail.reinfo.org"  "mail2.reinfo.org"
</VirtualHost>
  • ProxyRequests - turns on proxy
  • ProxyPass - specify when the proxy starts and where the server to proxy to. The start path could be root as shown, or could only part of the web site.
  • ProxyPassReverse - rewrite and redirects or URLs that coem fro the remote server so the proxy passes back URLs that will stay on the proxy.
  • ProxyPassReverseCookieDomain - Rewrite the URL in any cookies that are passed.


Enable httpd:

# /bin/systemctl enable httpd

Start httpd

# /bin/systemctl start httpd