引自:http://hi.baidu.com/anyhost/blog/item/e8f3aad4437ec204a18bb78d.html
大家好!我是anyhost,今天教大家如何給apache加密碼,訪問的時候需要用戶名和密碼,好了不用多說看下面的步驟
在apache的bin目錄裏面有一個htpasswd的可執行文件!先進到apache的bin目錄裏面哈!
#htpasswd -c /opt/web/.htpasswd anyhost //添加一個名爲anyhost的用戶。訪問web時的用戶名。
New password: //輸入你的密碼。
Re-type new password: //在次輸入你的密碼。
#vi /opt/web/.htgroup //創建一個.htgroup的文件。
pubs:anyhost web //添加組, pubs是組名anyhost和web是用戶名是屬於pubs組哈。這裏隨便加哈
ctrl^z //保存退出。
#vi /opt/web/.htaccess //創建一個.htaccess的文件。具體作用google一目瞭然。
AuthName My Only //name 可以隨便定義。
AuthType Basic //定義類型爲basic
AuthUserFile /opt/web/.htpasswd //指定用戶文件。就是我們剛纔創建的.htpasswd的文件。
AuthGroupFile /opt/web/.htgroup //指定用戶組。
require group pubs //定義pubs裏面的所有成員都可以訪問哈。這裏可以單獨指定某個用戶,user anyhost
ctrl^z //保存退出。
#vi /opt/web/apache/conf/httpd.conf //編輯apache的配置文件httpd.conf 。添加以下東東哈。
<directory "/mnt/date//web/"> //你 網頁的目錄
AuthType Basic //定義類型爲basic
AuthName "web" //登陸筐的名稱。
require user anyhost //指定anyhost用戶訪問。這裏也可以指定組,group pubs
authuserfile /opt/web/.htpasswd //指定用戶文件.
authgroupfile /opt/web/.htgroup //指定用戶組.
</Directory>
ctrl^z //保存退出。
#/etc/init.d/httpd restart //從新啓動apache