apache下配置认证用户

有时候我们须要给我apacheserver下制定的文件夹加上用户认证,方便一些而用户进行文件的浏览。配置例如以下:

1 设置用户

1
htpasswd -c file_path user_name

回车之后输入password就可以,请确保命令中的file _path有其它用户读的权限。

2 设置Apache

在/etc/apache2/apache2.conf或/etc/httpd/conf/httpd.conf中加入下面内容

1
2
3
4
5
6
7
8
<Directory /var/www/html/picture>
AuthName "Important Directory"  #登录时提示的内容
AuthType Basic  #认证方式
IndexOptions Charset=GB2312  #网页编码
Options Indexes FollowSymLinks MultiViews #以文件夹形式展示
AuthUserFile /opt/.apache_user #用户文件。1中file_path
Require valid-user 
</Directory>


若要隐藏server标示。请在配置文件里增加下面信息:

1
2
ServerSignature Off
ServerTokens Prod

很多其它文章请前往小胖轩.

原文地址:https://www.cnblogs.com/brucemengbm/p/6823508.html