How do I password protect a website using NGINX?

Linode Staff

I'm needing to password protect a (private) event website we are looking to host on our Linode so therefore need to apply a password to the homepage html file stored within a directory. Some research shows this is usually possible using .htaccess and .htpasswd files but it is dependent on server support for this. Do you know if this is possible with our Linode at all?

1 Reply

This is definitely possible with a Linode. The server support here is talking about the web server - in your case it's NGINX. NGINX doesn't support .htaccess files like Apache does, but it's still pretty simple to get basic password protection on your web page. NGINX has some great documentation, and I was able to find this one regarding how to set up some basic authentication:

Your server block configuration will vary depending on what you want password protected, but to protect the whole site just throw the auth_basic lines in the main portion of the block after you've run htpasswd to make your .htpasswd file:

server {
    listen  80;
    listen [::]:80;

    root /var/www/;
    index index.html;
    auth_basic "Password Protected";
    auth_basic_user_file /var/www/;

    location / {
        try_files $uri $uri/ =404;

After that, test out your config with sudo nginx -t and reload it by running sudo nginx -s reload. You should be all set!


Please enter an answer

You can mention users to notify them: @username

You can use Markdown to format your question. For more examples see the Markdown Cheatsheet.

> I’m a blockquote.

I’m a blockquote.

[I'm a link] (

I'm a link

**I am bold** I am bold

*I am italicized* I am italicized

Community Code of Conduct