我正在使用 nginx-auth-ldap 運行 NGINX 1.8.0。我有一個正在運行的應用程式/app
用於auth_ldap
身份驗證/授權。有用。
server {
listen 80;
...
location /app/ {
auth_ldap "Restricted";
auth_ldap_servers test;
...
}
}
我想授予額外bot
帳戶的存取權限來執行一些自動維護(Web API)。出於bot
安全原因,我無法建立 LDAP 帳戶。
我嘗試同時使用auth_ldap
and auth_basic
(後者為單一bot
使用者),但任何憑證都會導致 401。
server {
listen 80;
...
location /app/ {
auth_ldap "Restricted";
auth_ldap_servers test;
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htaccess
...
}
}
如果這行不通,您有其他建議如何繼續嗎?
注意:我嘗試在auth_basic
不同的位置鏡像該應用程式。存取控制有效,但應用程式對其 URL 進行硬編碼:來自/app-auth-basic
包含連結的回應返回到/app
.我無法控制該應用程序,因此這似乎不會導致任何結果。
server {
listen 80;
...
location /app/ {
auth_ldap "Restricted";
auth_ldap_servers test;
...
}
location /app-auth-basic/ {
auth_basic "Restricted";
auth_basic_user_file /etc/nginx/.htaccess
...
}
}
答案1
你幾乎是正確的,但缺少satisfy
指令:
server {
listen 80;
...
location /app/ {
satisfy any;
auth_ldap "Restricted LDAP";
auth_ldap_servers test;
auth_basic "Restricted htaccess";
auth_basic_user_file /etc/nginx/.htaccess
...
}
}
這樣,您將首先看到一個身份驗證對話框,其中顯示「受限 LDAP」(僅接受 LDAP 憑證)。如果您按一下“取消”,則會出現另一個驗證對話框,提示您“受限 htaccess”(僅接受 htaccess 檔案中的使用者/密碼)。請注意,如果您已在第一個對話方塊中輸入了正確的憑證,則第二個對話方塊永遠不會出現。
或者,您可以直接發送 htaccess 憑證以進入。http://user:[email protected]