Apache 實現用戶驗證 Authentication


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# 指定需要使用驗證登入的目錄
<Directory "/home/test">
Options Indexes MultiViews
AllowOverride AuthConfig # 需要進行驗證
Order allow,deny
Allow from all
</Directory>

# 在指定的目錄中生成 .htaccess
vim /home/test/.htaccess

AuthName "My Share File"
AuthType Basic
AuthUserFile /home/test/.htpasswd
require valid-user

# 在相對的目錄中生成相應的用戶的 .htpasswd
htpasswd -c /home/test/.htpasswd [username]

# 當要修改密碼時只需要將 -c 改為 -m
htpasswd -m /home/test/.htpasswd [username]

# 最後重新執行 Apache

參考: http://www.5ilinux.com/apache03.html