[ 永遠的UNIX::UNIX技術資料的寶庫 ]   GB | BIG5

首頁 > 應用技術 > Apache > 正文
Apache用戶認証方法匯總
http://sinbad.dhs.org 作者:吳阿亭 (2001-04-19 17:08:24)
一.基本的Apache用戶認証方法: 

若對某一目錄下的文件如/home/ftp/pub需要做到用戶認証,則在httpd.conf 
中加入下面的行 
<> 
options indexes followsymlinks 
allowoverride authconfig 
order allow,deny 
allow from all 

<> 
用在目錄/home/ftp/pub下放文件.htaccess,內容如下: 
authname "shared files" 
authtype basic 
authuserfile /etc/.passwd 
require valid-user 

用隨Apache來的程序htpasswd 生成文件/etc/.passwd,每行一個用戶名:密碼 

只要能提供正確的用戶名和密碼對,就允許登錄訪問,這是針對任何地址來的 
請求都要求提供用戶名和密碼認証。 

二.針對部分網段或地址要求認証。 

若公司LAN所在網段為192.168.0.0/24,且有一防火牆專線接入Internet, 
內部網卡的地址為192.168.0.1/32,則現在希望所有通過撥本地163通過 
防火牆上的apache反向代理向LAN上的另一WWW服務器訪問時需要認証,而本地 
LAN上的用戶不需認証。可以在httpd.conf中放入: 
〈Directory /home/ftp/pub> 
Options Indexes FollowSymLinks 
AllowOverride AuthConfig 
order deny,allow 
deny from 192.168.0.1 
〈/Directory> 

且在/home/ftp/pub/.htaccess中放入: 
AuthName "shared files" 
AuthType Basic 
AuthUserFile /etc/.passwd 
require valid-user 
satisfy any 

三.對同一目錄及其下的子目錄有不同的權限,僅某些人可以存取一目錄下的 
子目錄。 
如有一目錄/home/ftp/pub/sales,有三個用戶user1,user2,user3都需要用戶名 
和密碼進入/home/ftp/pub,但僅user1,user2能進入/home/ftp/pub/sales.則 
放下面的行到httpd.conf 

〈Directory /home/ftp/pub> 
Options Indexes 
AllowOverride AuthConfig 
order allow,deny 
allow from all 
〈/Directory> 

〈Directory /home/ftp/pub/sales> 
Options Indexes 
AllowOverride AuthConfig 
order allow,deny 
allow from all 
〈/Directory> 

且看/home/ftp/pub/.htaccess為: 
AuthName "shared files" 
AuthType Basic 
AuthUserFile /etc/.passwd 
require valid-user 

且看/home/ftp/pub/sales/.htaccess 
AuthName "shared files" 
AuthType Basic 
AuthUserFile /etc/.passwd 
AuthGroupFile /etc/.salesgroup 
require group manager 

且文件/etc/.passwd內容為: 
user1:passwd1 
user2:passwd2 
user3:passwd3 

且文件/etc/.salesgroup內容為: 
manager: user1 user2 
(http://www.fanqiang.com)
    進入【UNIX論壇

相關文章

======
 

★  樊強制作 歡迎分享  ★