1. 建立使用者及密碼
# /usr/bin/htpasswd -c /var/www/test/.htpasswd admin
New password:
Re-type new password:
Adding password for user admin
第二個使用者就不用加上 -c
# /usr/bin/htpasswd /var/www/test/.htpasswd abc[@more@]
2. 建立設定檔 /etc/httpd/conf.d/test.conf
# vim /etc/httpd/conf.d/test.conf
Alias /base /var/www/test
<Directory /var/www/test/>
Order Deny,Allow
#Deny from all
#Allow from 192.168.1.0/24
Require all denied
Require ip 192.168.1.0/24
AuthType Basic
AuthName “Restricted Files”
AllowOverride AuthConfig
# (Following line optional)
AuthBasicProvider file
AuthUserFile “/var/www/test/.htpasswd”
Require valid-user
</Directory>
3. 重新啟動 Apache Web Server
# systemctl restart httpd
# systemctl status httpd