Apache用戶認(rèn)證方法匯總 (轉(zhuǎn)載)
2024-08-27 18:28:37
供稿:網(wǎng)友
本文來源于網(wǎng)頁設(shè)計愛好者web開發(fā)社區(qū)http://www.html.org.cn收集整理,歡迎訪問。apache用戶認(rèn)證方法匯總
一.基本的apache用戶認(rèn)證方法:
若對某一目錄下的文件如/home/ftp/pub需要做到用戶認(rèn)證,則在httpd.conf中加入下面的行
<>
options indexes followsymlinks
allowoverride authconfig
order allow,deny
allow from all
<>
用在目錄/home/ftp/pub下放文件.htaccess,內(nèi)容如下:
authname "shared files"
authtype basic
authuserfile /etc/.passwd
require valid-user
用隨apache來的程序htpasswd 生成文件/etc/.passwd,每行一個用戶名:密碼
只要能提供正確的用戶名和密碼對,就允許登錄訪問,這是針對任何地址來的請求都要求提供用戶名和密碼認(rèn)證。
二.針對部分網(wǎng)段或地址要求認(rèn)證。
若公司lan所在網(wǎng)段為192.168.0.0/24,且有一防火墻專線接入internet,內(nèi)部網(wǎng)卡的地址為192.168.0.1/32,則現(xiàn)在希望所有通過撥本地163通過防火墻上的apache反向代理向lan上的另一www服務(wù)器訪問時需要認(rèn)證,而本地lan上的用戶不需認(rèn)證。可以在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
三.對同一目錄及其下的子目錄有不同的權(quán)限,僅某些人可以存取一目錄下的子目錄。
如有一目錄/home/ftp/pub/sales,有三個用戶user1,user2,user3都需要用戶名和密碼進(jìn)入/home/ftp/pub,但僅user1,user2能進(jìn)入/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內(nèi)容為:
user1:passwd1
user2:passwd2
user3:passwd3
且文件/etc/.salesgroup內(nèi)容為:
manager: user1 user2