Apache Reverse Proxy Configuration for Windows (Step by Step)


apache reverse proxy configuration for windows

Reverse Proxy allows you to receive requests and distribute them to one or more backend servers, thereby protecting your website from malicious attacks. It also helps you do load balancing. Let us take a look at Apache Reverse Proxy Configuration for Windows

 

Apache Reverse Proxy Configuration for Windows (Step by Step)

Here’s the Apache reverse proxy configuration for Windows. Before we proceed, please ensure that you have installed Apache on Windows.

 

1. Enable required modules

First, we need to enable the Apache modules responsible for reverse proxy management.

Open Apache’s config file in a text editor. It is generally located at


C:/Program Files/Apache Software Foundation/Apache2.2/conf/httpd.conf

If you have changed the installation directory, you will find the httpd.conf file in conf subfolder.

 

Make sure the following lines are uncommented. You can uncomment them by removing ‘#’ sign at their beginning.


LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so
LoadModule proxy_http_module modules/mod_lbmethod_byrequests

 

Restart Apache server to apply changes. This will enable reverse proxy modules in Apache.

 

 

2. Update Apache Config file

Open Apache’s config file in a text editor.

We will look at 2 ways to setup Apache reverse proxy

  1. Reverse Proxy with a single backend server
  2. Reverse Proxy with multiple backend servers

 

1. Reverse Proxy with single backend server

In the Apache config file, replace the VirtualHost block with the following lines:


<VirtualHost *:80>
 ProxyPreserveHost On
 ProxyPass / http://127.0.0.1:8080/
 ProxyPassReverse / http://127.0.0.1:8080/
</VirtualHost>

 

In the above lines,

  • ProxyPreserveHost – Passes the request header to the backend server.
  • ProxyPass – Proxy redirect directive. It maps all requests sent to this server to the backend server. So a request sent to http://example.com is sent to http://your_backend_server. So if you send example.com/product, it will be mapped to your_backend_server/product. It also returns the response from the backend server to the client.
  • ProxyPassReverse – Tells Apache to modify response headers. So in case of location redirect header, Apache will redirect the client to the proxy, and not the backend server.

Restart Apache Server to apply changes.

Now if you open a web browser and go to http://your_server, you’ll see a response from the back end server.

 

2. Load balancing across multiple backend servers

If you have a group of backend servers, here’s how you can distribute your traffic among them.

Open Virtual hosts and replace the Virtual Host block with the following lines of code


<VirtualHost *:80>
 <Proxy balancer://cluster>
  BalancerMember http://127.0.0.1:8080
  BalancerMember http://127.0.0.1:8081
 </Proxy>

 ProxyPreserveHost On
 ProxyPass / balancer://cluster/
 ProxyPassReverse / balancer://cluster/
</VirtualHost>

The above config is similar to the one with single backend server one, except that we use a ProxyBalancer directive to defines a cluster of backend servers, named balancer://cluster. Instead of calling it cluster, you can name it anything you want. In this case, ProxyPass and ProxyReversePass refer to the cluster, instead of a single IP address.

Restart Apache to apply changes.

That’s it! Now you know the Apache Reverse Proxy Configuration for Windows.

About Sreeram Sreenivasan

Sreeram Sreenivasan is the Founder of Ubiq, a business dashboard & reporting platform for small & medium businesses. Ubiq makes it easy to build business dashboards & reports for your business. Try it for free today!