
讀取 nginx 的ngx_http_access_模組的文檔,我發現了這個:
如果規則很多,則使用ngx_http_geo_模組模組變數是更好的選擇。
如何使用 geo 模組允許/拒絕?如果我這樣做:
geo $listofips {
default 0;
8.8.8.8 1;
}
server {
# [...]
allow $listofips;
deny all;
}
它給了我以下錯誤:
/path/to/config:97 中的參數「$listofips」無效
如何使用 geo 模組進行存取控制?我無法使用 ifs,因為它顯然會損壞try_files
(請參閱 nginx 的 IfIsEvil)。
答案1
如果不使用 IF 我確信在編寫此答案時這是不可能的。
所以在這種情況下看起來像這樣:
geo $trusted_user {
default 0;
8.8.8.8 1;
}
server
{
if ( $trusted_user = 0 ) {
return 403;
}
}
向 NGINX 團隊發送建議: https://www.nginx.com/
這個問題是根據這個回應回答的:NGINX - 有條件地允許或拒絕 IP
搜尋來源“# try_files 由於 if 而無法運作”在“例子”: https://www.nginx.com/resources/wiki/start/topics/深度/ifisevil/#examples