Apache使用者認證

2021-04-29 04:13:17 字數 2253 閱讀 3795

一.基本的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 

apache使用者認證

一 修改http.conf檔案 options indexes allowoverride authconfig 表示進行身份驗證 order allow,deny allow from all 其中第4行allowoverride項要設定成authconfig,表示允許.htaccess文件中的認...

apache的使用者認證

documentroot data wwwroot www.123.com servername www.123.com 使用者認證 指定認證的目錄 allowoverride authconfig 這個相當於開啟認證的開關 authname 123.com user auth 自定義認證的名字,作...

Apache使用者認證方法彙總

一.基本的apache使用者認證方法 若對某一目錄下的檔案如 home ftp pub需要做到使用者認證,則在httpd.conf 中加入下面的行 options indexes followsymlinks allowoverride authconfig order allow,deny all...