How to secure your Nginx HTTP Server using Basic HTTP Authentication


apt-get install nginx apache2-utils

Nginx Configuration

Generate the username/password pairs using htpasswd

sudo htpasswd -c /etc/apache2/.htpasswd user1
sudo htpasswd /etc/apache2/.htpasswd user2

or use this website

The Nginx Configuration would look like this

location /api {
    satisfy all;
    auth_basic           "Administrator’s Area";
    auth_basic_user_file /etc/apache2/.htpasswd;
    deny  all;

The satisfy here means that both the IP and the passwords have to match


About Me

My name is Omar Qunsul. I write these articles mainly as a future reference for me. So I dedicate some time to make them look shiny, and share them with the public.

You can find me on twitter @OmarQunsul, and on Linkedin.

And btw, if you like playing chess, please give my personal multiplayer Chess Website ChessDuo a try.