如何locking安装在ngix上的debian服务器中的目录?

我尝试了很多方法,并坚持使用它。 我编辑/etc/nginx/nginx.conf并编写这些行。

 location /home/user/domains/example.com/public_html/lockfolder/ { auth_basic "Restricted"; auth_basic_user_file /home/user/domains/example.com/.htpasswd; } 

我使用crypt(3)encryption通过命令mkpasswd创build密码。 然后我用给定的程序user:encryptedpasswd.htpasswd

但事情并不如说。 让我知道如果有人知道我可以如何完全configuration我的目的! 我也用/etc/init.d/nginx reload加载我的nginx

location /home/user/domains/example.com/public_html/lockfolder/行是错误的,因为它使用文件系统path,而location使用URI。 正确的configuration将看起来像

 location /lockfolder/ { auth_basic "Restricted"; auth_basic_user_file /path/to/htpassd; } 

预计将请求限制在http://www.example.com/lockfolder/something

另一个可能的陷阱是其他位置,特别是更具体的位置和/或正则expression式。 你必须确保你写的位置实际上匹配你想要匹配的请求。 有关位置匹配详细信息的文档,请参阅http://nginx.org/r/location

尝试这个:

 location /lockfolder { auth_basic "Restricted"; auth_basic_user_file htpasswd; } 

从版本0.6.7开始,auth_basic_user_filepath相对于nginxconfiguration文件nginx.conf的目录。 如果安装了Apache,则可以使用包含的htpasswd程序创build密码文件。

HttpAuthBasicModule文档