Here are all kinds of examples of htpasswd files I use on a regular basis. Hopefully they can be useful for your application.
First thing is first for any htpasswd. You need the users so we will create them here. The secure location if up to you.
Basic .htaccess file. Create this in the directory you want to protect. Once this is installed all directories below this one will be protected.
Blocking all users except those who authenticate or come from one of the following IP address with the X-Forwarded-For header. This is great for those who have a load balancer in-front of their solution.
How about using MySQL for authentication? I am assuming you have Apache2 and MySQL/Percona/MariaDB already installed. We are only covering the installation of the Apache module, creating the tables and activating.
For Red Hat Enterprise Linux 6 and 7, CentOS 6 and 7, Fedora, Scientific Linux and all other RHEL 6 and 7 based distro’s.
For Debian, Ubunutu and other distro’s based on Debian.
Brian has spent more than fifteen years as Unix enthusiast, specalising in systems administration and solutions architecture for SMB's to Fortune 100 companies. His career has focused on emerging and niche technologies to major advancements in the industry - most notibly cloud.