有時候我們需要給我apache服務器下制定的目錄加上用戶認證,方便一些而用戶進行文件的瀏覽。配置如下:
1 設置用戶
1
|
htpasswd -c file_path user_name
|
回車之後輸入密碼即可,請確保命令中的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> |
若要隱藏服務器標示,請在配置文件中加入以下信息:
1
2 |
ServerSignature Off
ServerTokens Prod |
更多文章請前往小胖軒.