apache,

How to create Apache reverse proxy for your application

Sep 23, 2021 · 1 min read · Post a comment
How to create Apache reverse proxy for your application

Creating Apache reverse proxy follows a similar procedure as Nginx. In some of the previous posts, we saw how to set up Nginx reverse proxy, so today I’m going to show you exactly the same thing but instead of Nginx, we will use Apache.

Prerequisites

  • Debian based distro
  • Apache

Enable Apache proxy modules

Firstly if you don’t have enabled the proxy apache modules, you can do it with the following command:

a2enmod proxy
a2enmod proxy_http

Create a reverse proxy

Step 1. Navigate to the Apache config directory:

sudo cd /etc/apache2

Step 2. Open your desired virtual host file. In this example I’m going to open the default one:

sudo nano /etc/apache2/sites-enabled/000-default.conf

Step 3. Let’s say your application listens on port 8069 and you want to access it on port 80. Put the following configuration to create a reverse proxy:

<VirtualHost *:80>
    ServerName domain.io
    DocumentRoot /var/www/html/domain.io 
    ErrorLog logs/domain.io-error_log
    CustomLog logs/domain.io-access_log common

    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>

    ProxyPass / http://domain.io:8069/
    ProxyPassReverse / http://domain.io:8069/
</VirtualHost>

Step 4. Now we need to restart the Apache server, so the changes can take effect.

service apache2 restart

Once the server is restarted you can access your app on port 80.

Conclusion

When it comes to reverse proxy I always prefer Nginx as a better option, but if you are more familiar with Apache you can follow the steps above and you will achieve the same thing. Feel free to leave a comment below and if you find this tutorial useful, follow our official channel on telegram.