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
)

Pre-requisites

– 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/mod_proxy.so

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,

http://192.168.1.50

where, 192.168.1.50 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 / http://192.168.1.50/

ProxyPassReverse / http://192.168.1.50/

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

$ sudo systemctl restart httpd

Note:-
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 / http://192.168.1.50:8080/test/

ProxyPassReverse / http://192.168.1.50:8080/test/

Testing the reverse proxy

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

http://192.168.1.100/

here 192.168.1.100 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:
Facebook

|
Twitter

|
Google Plus

Linux TechLab is thankful for your continued support.

LXer

责编内容by:LXer阅读原文】。感谢您的支持!

您可能感兴趣的

OptionsBleed – The Apache HTTP Server Now Bleeds A new vulnerability in the Apache HTTP server was found recently. Designated as CVE-2017-9798, this vulnerability lies in how Apache handles certain ...
Validating overlay network when docker swarm runni... I got a chance to revisit my docker swarm deployment this week after a bit of a break. I was a little curious about my setup because when I spoke to...
Vue.js 踩坑记 (三) 要学Vue.js 其实还是需要对node.js有一定的了解,下面用官方例子搭一个http服务器,然后访问他的时候返回一个Hello World 一共需要3步完成 1.引入 required 模块:我们可以使用 require 指令来载入 Node.js 模块。 2.创建服务器:服务器可以...
VMware Fusion 中如何复制CentOS/Linux虚拟机 想在Mac本上安装几个CentOS的虚拟机,尝试搭建Hadoop的全分布环境。一台台虚拟机安装过去太麻烦了,想直接将现有的CentOS虚拟机复制几份完事,但是复制出来的虚拟机无法上网,折腾了一翻,最终完满解决,记录于此。 环境:mac OSX(10.10.2) + vmware fusion(...
Nginx搭建反向代理服务器 一、什么是反向代理?反向代理的作用? 反向代理(Reverse Proxy)方式是指以代理服务器来接受internet上的连接请求,然后将请求转发给内部网络上的服务器,并将从服务器上得到的结果返回给internet上请求连接的客户端,此时代理服务器对外就表现为一个反向代理服务器。 当外部客户...