有时候我们的文档,一般分为对内和对外开发两部分,但是文档内容是静态html,因此需要在nginx层做访问权限控制
譬如: /doc/site-description-guide
路径下的url都不让访问:
1.在nginx中添加配置
location /doc/site-description-guide
{
auth_basic "Please enter Password";
auth_basic_user_file nginx_htpasswd.pl;
}
2.我的nginx安装在/usr/local/nginx/
,配置文件路径为:/usr/local/nginx/conf
cd /usr/local/nginx/conf
touch nginx_htpasswd_generate.pl
vim nginx_htpasswd_generate.pl
vim打开文件后,在文件里面填写如下内容:
#!/usr/bin/perl
use strict;
my $pw=$ARGV[0];
print crypt($pw,$pw)."\n";
:wq
保存退出后,执行chmod 755 nginx_htpasswd_generate.pl
然后执行:
./nginx_htpasswd_generate.pl fecshop
feIffq1p5TTrU // 执行结果
然后创建文件 nginx_htpasswd.pl,写入账号密码
touch nginx_htpasswd.pl
chmod 755 nginx_htpasswd.pl
vim nginx_htpasswd.pl
打开文件后,写入内容
myfecaccount:feIffq1p5TTrU
:wq 保存退出,然后重启或者重新加载nginx配置
/etc/init.d/nginx reload
然后访问 /doc/site-description-guide
路径下的url ,就会出来一个账号密码确认,
填写上面设置的账号密码即可登录
账号:myfecaccount
密码:fecshop
然后就可以愉快的登录了