Remove .htpasswd Password Protection (Nginx)

Posted July 29, 2015 25k views

I added an htpasswd.txt to sites-avaiable/default to protect my site:

server {
        auth_basic "closed site";
        auth_basic_user_file /tmp/.htpasswd.txt;

        listen 81 default_server;
        listen [::]:80 default_server ipv6only=on;

        root /var/www/path/to/root
        index index.html index.htm;

        server_name ipaddress;

Now that i’m trying to remove it, I can’t get rid of a .htpasswd protection I set up previously. I’ve tried everything from creating .htaccess in the root of my site with satisfy any like this post suggests and this, to deleting the reference to htpasswd.txt from my sites-available/default file, to reinstalling nginx. I can’t find where this htpasswd file is being referenced somewhere from because nothing seems to get rid of it. Lastly I tried deleted the htpasswd.txt file and that just broke the login.

I want the whole site to be available with no htpasswd.

I also did a grep search to find out if the htpasswd file is being called for and it’s no where to be found. What can I do?

edited by kamaln7

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Submit an Answer
7 answers

@sugarhill thabks for your answer. I’ve tried that but the password prompt still appears.

This is how I did it on my password protected nginx site:

  • simply remove all “authbasic” parameters from nginx server block
  • remove .htpasswd (it’s a hidden system file) from /var/www/html (or whatever your public website path is)

@sugarhill yup. I feel it may be referenced somewhere else but I’ve looked everywhere. Cant get rid of this password prompt.

  • ok, the only other thing I could think of would be a duplicate in some other config file e.g. at

    • sites-available/ (anything else here besides “default”)
    • sites-enabled/ (same here)
    • or inside /etc/nginx/nginx.conf

@sugarhill thats a good idea. So you would duplicate in nginx.conf and use authbasic “none”;?

There’s nothing in sites-enabled but I can try copying the default file to there and doing it.

  • No, there’s no need to duplicate or copy anything. I just thought “authbasic” might be hiding inside one of these files.

    Before you get the wrong impression, I’m not an nginx expert - I just wanted to let you know what worked for me. In my case there was no need to add anything like authbasic “none;”, I simply removed all code that included authbasic in my nginx server block, then removed the hidden pasword system file in the websites root folder - restart the server and I was done.

    Hopefully there are more knowledgable members around who can solve your problem.

@sugarhill no problem at all. I simply have spent a day and a half stuck on this and i’m drained of ideas. Any other input is welcome and you’ve given me a couple so thanks. I actually tried those other files as well and nothing is there. Thanks again.

  • Removing the auth_* directives and restarting nginx should be enough to disable the password authentication requirement. Have you tried clearing your browser’s cache? Do others see the password prompt as well?

@kamaln7 thanks for your response. By auth* you mean authbacic and authbasicuser_file correct? Yes I deleted those and I still get the password block.

Yes, i’ve tried on multiple browsers and other people still see it as well. I just tried creating an .htaccess file in my root to override but no luck.

My suggestion to anyone with a problem such as this involving unknowns that cannot be dealt with after much effort: Go to your Server (in my case digital ocean) and create a new (take a snapshot of your server to apply to your new IP) IP / droplet for your site. Uninstall your server engine (Nginx or Apache) and reinstall on the new server / IP. It’s a little annoying but at least you wont be stuck like I was for days. Thanks to @kamaln7 and @sugarhill for the help.