顯示具有 Apache 標籤的文章。 顯示所有文章
顯示具有 Apache 標籤的文章。 顯示所有文章

2011年8月4日 星期四

Apache 實現用戶驗證 Authentication

# 指定需要使用驗證登入的目錄
<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
service httpd restart