htpasswd with Nginx1 min read


Hi All, this document deals with the web page security using

  •  Prerequisites


  • we use this is found in the apache- package
    sudo apt-get install apache2 apache2-utils
  • Now we create a password file, for the first time we need to use -C option to create the specified file, We mention the user name at the end of the command, it will prompt to enter password
    htpasswd -c /etc/apache2/.htpasswd <user_name>
    htpasswd -c /etc/apache2/.htpasswd techrunnr

  • If you want to add another new user then remove -c
    htpasswd  /etc/apache2/.htpasswd techrunnr1
  • Now we are going to mention the file into the configuration, mention the file location as show below (In this am securing )
    server {
                    location /techrunnr/ {
                            auth_basic "Restricted Content";
                            auth_basic_user_file /etc/apache2/.htpasswd;

    auth_basic “Restricted Content”;
    auth_basic_user_file /etc/apache2/; lines are added into the file

  • Now restart the service
    systemctl restart nginx
  • Now go to the http://localhost/techrunnr/, It will prompt for a user name and password, Now your page is secured

We need your support!!
Other Amount:
Questions Answered
Articles Written
Overall Points

You may also like...

Leave a Reply