Apache Reverse Proxy with Authentication Example

By Hardik Savani October 28, 2021 Category : Ubuntu

Today, apache reverse proxy with authentication example is our main topic. In this article, we will implement an apache reverse proxy with basic authentication. In this article, we will implement an apache reverse proxy to add basic authentication. if you have a question about how to add basic authentication in apache reverse proxy then I will give a simple example with a solution.

Sometimes we made a configuration of reverse proxy with port using apache configuration. you basically added ProxyPass and ProxyPassReverse config. it's working fine but anyone can access your IP or domain. If you want to add basic authentication using apache then I will give you simple example commands for the ubuntu server.

Let's see bellow command:

Install apache2-utils

Here, we need to install apache2-utils package.

sudo apt-get install apache2-utils

Set Username and Password

Now, set username and password that you want to keep.

sudo htpasswd -c /etc/apache2/.htpasswd <username>

Add Proxy

Here, we will add Proxy tag for basic authentication.

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

<VirtualHost *:80>

ProxyPass / http://127.0.0.1:47334/

ProxyPassReverse / http://127.0.0.1:47334/

Timeout 5400

ProxyTimeout 5400

ServerName localhost

<Proxy *>

Order deny,allow

Allow from all

Authtype Basic

Authname "Password Required"

AuthUserFile /etc/apache2/.htpasswd

Require valid-user

</Proxy>

</virtualhost>

Now, let's restart apache2.

sudo service apache2 reload

Now, you can check your IP or domain with basic authentication as bellow:

i hope it can help you...

Tags :
Shares