Nginx - 密码保护目录

时间:2012-09-16 10:45:50

标签: shell nginx passwords

我想用密码保护我的整个网站。我正在运行Debian Squeeze。假设我希望我的用户名为“Jane”,密码为“V3RySEcRe7”。

在我的app-nginx.conf中:

auth_basic "Restricted"; auth_basic_user_file /etc/nginx/htpasswd;

在我的shell脚本中,我有这个:

printf "Jane:$(openssl passwd -1 V3RySEcRe7)\n" >> /etc/nginx/htpasswd

当我访问我的网站时,它受密码保护,但我使用的凭据不起作用。我在哪里错了?

1 个答案:

答案 0 :(得分:9)

我相信你现在已经解决了这个问题,但我想我会为其他人添加这个:

Nginx documentation对此有点神秘,但确实应该使用“基于MD5的密码算法(apr1)的Apache变体”来生成密码哈希。因此,使用 -apr1 标志而不是-1将起作用:

printf "Jane:$(openssl passwd -apr1 V3RySEcRe7)\n" >> /etc/nginx/htpasswd