<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>https://briansnelson.com/index.php?action=history&amp;feed=atom&amp;title=Protecting_Folders_with_Nginx</id>
		<title>Protecting Folders with Nginx - Revision history</title>
		<link rel="self" type="application/atom+xml" href="https://briansnelson.com/index.php?action=history&amp;feed=atom&amp;title=Protecting_Folders_with_Nginx"/>
		<link rel="alternate" type="text/html" href="https://briansnelson.com/index.php?title=Protecting_Folders_with_Nginx&amp;action=history"/>
		<updated>2026-06-04T07:10:05Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.24.1</generator>

	<entry>
		<id>https://briansnelson.com/index.php?title=Protecting_Folders_with_Nginx&amp;diff=829&amp;oldid=prev</id>
		<title>Brian: Created page with &quot;==Protecting Folders with Nginx==  This question comes up every so often, and its actually fairly easy besides the fact you do not use an .htaccess file. To do so we’ll need...&quot;</title>
		<link rel="alternate" type="text/html" href="https://briansnelson.com/index.php?title=Protecting_Folders_with_Nginx&amp;diff=829&amp;oldid=prev"/>
				<updated>2015-03-08T04:08:57Z</updated>
		
		<summary type="html">&lt;p&gt;Created page with &amp;quot;==Protecting Folders with Nginx==  This question comes up every so often, and its actually fairly easy besides the fact you do not use an .htaccess file. To do so we’ll need...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Protecting Folders with Nginx==&lt;br /&gt;
&lt;br /&gt;
This question comes up every so often, and its actually fairly easy besides the fact you do not use an .htaccess file. To do so we’ll need the auth_basic module which comes included with Nginx.&lt;br /&gt;
&lt;br /&gt;
First we will need to create a password file, you can create this in the folder you wish to protect (though the file can reside anywhere Nginx has access to).&lt;br /&gt;
&lt;br /&gt;
===Create the .htpasswd file===&lt;br /&gt;
&lt;br /&gt;
 htpasswd -c /var/www/domain.com/.htpasswd username&lt;br /&gt;
&lt;br /&gt;
When you run the above command, it will prompt you for a password for the provided username, and then create the file .htpasswd in the folder you specified. If you already have a pre-existing password file, you can omit the -c flag. You can use the -D flag to remove the specified user from a password file.&lt;br /&gt;
&lt;br /&gt;
===Setting up Nginx===&lt;br /&gt;
&lt;br /&gt;
Adding protection to your admin folder or for wordpress wp-admin folder&lt;br /&gt;
&lt;br /&gt;
 server {&lt;br /&gt;
 ... &lt;br /&gt;
     location /admin {&lt;br /&gt;
         auth_basic &amp;quot;Welcome to the DarkSide&amp;quot;;&lt;br /&gt;
         auth_basic_user_file /var/www/domain.com/.htpasswd;&lt;br /&gt;
     }&lt;br /&gt;
 ... &lt;br /&gt;
 }&lt;br /&gt;
&lt;br /&gt;
With the above access to the admin directory will prompt the user with a basic authentication dialog, and will be challenged against the password file provided.&lt;br /&gt;
&lt;br /&gt;
The password file itself does not have to be named .htpasswd, but if you do store it a web-accessible location make sure to protect it. With the last location block above using any name with a period in front should be protected from web-access.&lt;br /&gt;
&lt;br /&gt;
The safest place to store a password file is outside of the web-accessible location even if you take measures to deny access. If you wish to do so, you can create a protected folder in your nginx/conf directory to store your password files (such as conf/domain.com/folder-name/password) and load the user file from that location in your configuration.&lt;/div&gt;</summary>
		<author><name>Brian</name></author>	</entry>

	</feed>