User Tools

Site Tools


wiki:password_protect_nginx_site

Password protect nginx site

Install the apache2-utils package on your server by typing:

apt-get update && apt-get install apache2-utils

The first time we use this utility, we need to add the -c option to create the specified file. We specify a username (sammy in this example) at the end of the command to create a new entry within the file:

htpasswd -c /etc/nginx/.htpasswd sammy

You will be asked to supply and confirm a password for the user.

Leave out the -c argument for any additional users you wish to add:

Blocking specific path

Asks for password when trying to download from https://example.com/wp-content/uploads/file.png

location ^~ /wp-content/uploads/file.png {
                try_files $uri $uri/ /index.php?$args;
		auth_basic "Restricted Content";
            	auth_basic_user_file /etc/nginx/.htpasswd;
            }

Tested on

See also

References

wiki/password_protect_nginx_site.txt · Last modified: 2021/07/09 10:14 by antisa

Except where otherwise noted, content on this wiki is licensed under the following license: CC0 1.0 Universal
CC0 1.0 Universal Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki