1. 建立帳號密碼檔
1.1 初次建立,或是想清空之前紀錄,請加參數 -c
htpasswd -c /etc/httpd/.htpasswd user1
New password: <輸入user1的密碼>
Re-type new password: <確認密碼>
Adding password for user user1

1.2 接著建立第二位以上的user,千萬不要加參數 -c 
htpasswd /etc/httpd/.htpasswd user2
New password: <輸入user1的密碼>
Re-type new password: <確認密碼>
Adding password for user user2

2. 編輯 .htaccess
2.1 假設網站路徑是 /var/www/html/admin
vi /var/www/html/admin/.htaccess
AuthName "admin login"
AuthUserFile /etc/httpd/.htpasswd
AuthType Basic
require valid-user

開啟網頁測試,正確的話,會跳出一個帳號密碼對話框
輸入剛剛建立的帳號密碼即可登入
 

image

 

arrow
arrow
    文章標籤
    apache password
    全站熱搜

    helloworld 發表在 痞客邦 留言(0) 人氣()