Apache Reverse Proxy Http

Posted on  by admin

Reverse-Proxy – A useful Tool. A reverse proxy is a tool that intercepts and handles http(s) requests. The reverse proxy can forward it to different servers, caching the response, thus relieving the underlying web servers or distributing the load to uniformly different systems. All in all, a very handy tool for busy services or multiple small. Apache is a very popular HTTP server and can be configured as a proxy to redirect HTTP traffic similar to nginx. In this guide, we will learn how to set up Apache on CentOS 7 and use it as a reverse-proxy to welcome incoming connections and redirect them to the ASP.NET Core application running on Kestrel.

This tutorial will help you to setup Apache web server as Reverse Proxy for the Tomcat hosted applications.

Setup Scenario

Tomcat is running on port 8080 and I have configured two sample applications running with following urls.

  • http://localhost:8080/sample
  • http://localhost:8080/calendar

Now I have installed Apache server on same host running on port 80. I will use Apache server to get users requests and transfer these requests to corresponding applications running on back-end Tomcat server on port 8080. I need to configure Apache to transfer requests to tomcat like below:

  • http://example.com >> http://localhost:8080/demo1/
  • http://example.net >> http://localhost:8080/demo2/
  • http://domain.com/demo1/ >> http://localhost:8080/demo1/
  • http://domain.com/demo2/ >> http://localhost:8080/demo2/
Apache ssl reverse proxy

Let’s start the configuration

1. Enable Mod Proxy Apache Module

By default this module is enabled in Apache for users who installed using rpm packages. If you don’t have enabled edit your Apache configuration /etc/httpd/conf/httpd.conf or for Apache 2.4 /etc/httpd/conf.modules.d/00-proxy.conf file and uncomment following lines or put in file.

For the Debian based systems use the following command to enable the Proxy module with Apache.

Apache Reverse Proxy Https Centos 7

2. Configure Apache Virtual Hosts

Now will start working with virtual host. We are creating three virtual hosts as below. You create only which is required with needed modifications. Edit Apache main configuration file and start with the configuration.

VirtualHost Example 1 :-

To forward all requests sent to example.com to backend tomcat server corresponding application like:

  • http://example.com >> http://localhost:8080/demo1/

Configure virtual host like this.

VirtualHost Example 2 :-

To forward all requests sent to example.net to backend tomcat server corresponding application like:

  • http://example.net >> http://localhost:8080/demo2/

Configure virtual host like this.

VirtualHost Example 3 :-

Apache Reverse Proxy Http To Https Redirect

To forward all requests sent to sub directory /demo1/ or /demo2 on http://domain.com to back-end tomcat corresponding applications like:

  • http://domain.com/demo1/ >> http://localhost:8080/demo1/
  • http://domain.com/demo2/ >> http://localhost:8080/demo2/
Apache Reverse Proxy Http

Configure virtual host like this.

3. Restart Apache and Test

After making all necessary changes restart Apache service using the following command and access your sites in a web browser. Make sure you are getting proper pages from tomcat.