在 ldap 身份驗證后面有一個 nginx 反向代理。我可以從變數 $_SERVER['PHP_AUTH_USER'] 讀取 php 中的用戶名。我認為這意味著用戶名是從 ldap 傳遞到 nginx 而不是 php。
在 nginx 配置中是否可以只允許用戶串列訪問檔案夾?
更新
在 nginx 中,用戶存盤在 $remote_user 變數中。是否可以將 $remote_user 與存盤在檔案中的用戶串列進行比較?然后拒絕或允許訪問檔案夾?
更新
可能我必須使用map指令,例如:
map $remote_user $allowed_user {
default 0;
user1 1;
user2 1;
}
然后在適當的位置進行測驗:
location /folder/ {
if($allowed_user != 1){
return 403;
}
proxy_pass http://site;
}
但是當我這樣做時sudo nginx -t,我收到以下錯誤:
nginx: [emerg] unknown directive "if($allowed_user" in /etc/nginx/nginx.conf:104
nginx: configuration file /etc/nginx/nginx.conf test failed
uj5u.com熱心網友回復:
您可以通過map指令來完成(請注意,map翻譯定義塊應該放在塊外的http背景關系中server):
map $remote_user $deny
username1 0;
username2 0;
...
usernameN 0;
default 1;
}
server {
...
location /folder/ {
if ($deny) { return 403; }
...
}
}
您可以以上述形式 ( username1 0; username 2 0; ...)預先生成用戶串列,然后將此串列包含到 nginx 配置中:
map $remote_user $deny {
include /path/userlist.txt;
default 1;
}
每當此用戶串列檔案發生更改時,您都需要重新加載 nginx 配置 ( nginx -s reload)。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/315297.html
