2011-09-12 220 views
1

我想使用Apache服務器爲一個目錄設置密碼,以便只有授權人員才能訪問該目錄。我在目錄中創建了.htpasswd文件。它包含一行Apache中的密碼保護目錄

username:$apr1$5H33Pfw6$WApVs3KlrU7QgBqYrFgeW. 

密碼是「密碼」。而我的目錄偏好

<Directory /> 
AuthType Basic 
AuthName "Example Repository" 
AuthUserFile /.htpasswd 
Require valid-user 
</Directory> 

當訪問來自瀏覽器,它會詢問用戶名和密碼的目錄。輸入用戶名和密碼請求失敗。 Http請求錯誤代碼是403.可能是錯誤。謝謝。

回答

1

http://httpd.apache.org/docs/2.2/mod/mod_authn_file.html

語法摘自:AuthUserFile文件的文件路徑

文件的路徑是用戶文件。如果它不是絕對的,則將其視爲相對於ServerRoot。

+0

我已嘗試完整路徑也。但沒有成功。 AuthUserFile C:/Repositories/Test.git/.htpasswd –

+0

我應該輸入哈希密碼。 –

+0

你說你得到HTTP錯誤代碼403.哪一個是由Wiki:與401未授權的響應不同,驗證將沒有區別。所以我的猜測是,在你的配置中的其他地方什麼是錯的。 – unNamed

1

您必須提供您的.htpasswd文件的完整路徑。嘗試使用

AuthUserFile /complete/passwd/file/path/.htpasswd 

希望它有幫助。

+0

我已嘗試完整路徑也。但沒有成功。 AuthUserFile C:/Repositories/Test.git/.htpasswd –

+0

我應該輸入散列密碼嗎? –

+0

嘗試用雙引號:AuthUserFile「C:/Repositories/Test.git/.htpasswd」 – geezmo