Nginx - 密码保护目录

J.Z*_*Zil 2 passwords shell nginx

我想密码保护我的整个网站.我正在运行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

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

小智 10

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

Nginx的文档是对这个有点神秘,但确实提到了"基于MD5密码算法(APR1)的阿帕奇变种"应该被用来生成密码哈希.因此使用-apr1标志而不是-1将起作用:

printf "Jane:$(openssl passwd -apr1 V3RySEcRe7)\n" >> /etc/nginx/htpasswd
Run Code Online (Sandbox Code Playgroud)