How to use Apache as Reverse Proxy on CentOS & RHEL

存储架构 2017-12-16 阅读原文

Reverse proxy is a kind of proxy server that takes http or https request & transfers/distributes them to one or more backend servers. Reverse proxy is useful in many ways, like

– It can hide the origin serve, thus making it more secure & immune to attacks,

– It can act as a load balancer,

– Reverse proxy can also be used to encrypting/decrypting webserver traffic, thus taking some load off from the backend servers.

– It can also be used for caching static as well as dynamic contents, which also reduces load off the web servers.

In this tutorial, we are going to discuss how we can use Apache as reverse proxy server on CentOS/RHEL machines. So let’s start with the per-requisites needed for creating apache as reverse proxy,

(Recommended read : Easiest guide for creating a LAMP server on CentOS/RHEL


– We will be using both apache as reverse proxy as well as backend server, though we can also use some other application or webserver like wildfly or nginx as backend servers . But for the purpose of this tutorial, we will be using apache server only.

So we need to have Apache server installed on both the servers. Install apache with the following command,

$ sudo yum install httpd

For detailed installation of Apache webserver, refer to our article

‘Step by Step guide to configure APACHE server.

Modules needed for using Apache as reverse proxy

After the apache has been installed on the machine, we need to make sure that following modules are installed & activated on the apache machine, that will be used as reverse proxy,

1- mod_proxy –it is the main module responsible for redirecting the connections,

2- mod_proxy_http –add the support for proxying HTTP connections,

Check if the following modules are installed & working with the following command,

$ httpd -M

This command will generate the list of modules that are currently working . If these modules are not among the list, than we need to enable them by making the following entry in httpd.conf,

$ sudo vim /etc/httpd/conf/httpd.conf

LoadModule proxy_module modules/

LoadModule proxy_http_module modules/mod_proxy_h

Now save the file & exit, than restart the apache service to implement the changes made,

$ sudo systemctl restart httpd

Configuring Backend test server

We have also installed apache on backend server & will now add a simple html page for testing purposes,

$ sudo vim /var/www/html/index.html

Test page for Backend server

This is a simple test page hosted on backend server.

Save the file & exit. Now restart the apache service to implement the changes made. Next test the page from a browser on local or remote system with the following URL,

where, is the IP address of the backend server.

Configuring simple reverse proxy

After the backend server is ready, next thing to do is to make our front end i.e. reverse proxy ready. To do so, we need to make the following entry in apache configuration file i.e. httpd.conf,

$ sudo vim /etc/httpd/conf/httpd.conf

ProxyPreserveHost On

ProxyPass /

ProxyPassReverse /

here, we are telling with ‘ProxyPass’ parameter that whatever request s received at ‘/’ , redirect it to ‘’. Now restart the apache services to implement the changes,

$ sudo systemctl restart httpd

We can also add port numbers here, like for example we are using this reverse proxy with tomcat as backend server, we can also this frontend server as reverse proxy for apache tomcat with the following entries in httpd.conf,

ProxyPreserveHost On

ProxyPass /

ProxyPassReverse /

Testing the reverse proxy

To test the reverse proxy, open the following URL from a web browser,

here is the IP address of the reverse proxy server. As soon as the URL loads up, we can than see the page that was hosted on backend server. This shows that our reverse proxy is correctly configured & working.

In our future tutorial, we will learn how to configure the apache reverse proxy as loadbalancer. Please do leave any questions/queries you have in the comment box below.

If you think we have helped you or just want to support us, please consider these :-

Connect to us:


Google Plus

Linux TechLab is thankful for your continued support.




Filebeat modules, access logs and Elasticsearch st... Elastic recently introducedFilebeat Modules, which are designed to make it extremely easy to ingest and gain insight...
centos 安装modeldb 踩坑之旅 Type=Application Name=Pycharm GenericName=Pycharm3 Comment=Pycharm3:The Python IDE Exec=sh /usr/loc...
谁说前端不需要懂-Nginx反向代理与负载均衡... 学到老活到老 前端圈一直很新,一直要不停的学习,而且在进入大厂的路上,还要求熟悉一门后台语言等等。用一句别人开玩笑的话来说,java十年前的技术现在还能用,而前端的技术就不是这样的了 突然想起了deno项目发布的时候,一个搞笑的is...
Let’s Get Away From Slime Sourcing Let’s Get Away From Slime Sourcing Slime sourcing: it’s to the letter of libre licenses, but it’s certainly not to th...
注册中心 Eureka 源码解析 —— 网络通信... 摘要: 原创出处 「芋道源码」欢迎转载,保留摘要,谢谢! 本文主要基于 Eureka 1.8.X 版本 1. 概述 2. Eur...