
我正在嘗試設定 Nginx v.1.24.0 和 GeoIPupdate 來工作,以便非來自特定國家/地區的使用者無法存取 Web 伺服器。
然而,當我遵循每一個指南時,我發現它已經過時了,要么這些連結不起作用,因為 MaxMind 刪除了它們,要么他們認為我有需要安裝的模組。
即使官方 Nginx wiki 也沒有幫助(https://nginx.org/en/docs/http/ngx_http_geoip_module.html)
我束手無策,不知道該怎麼辦。我想要做的就是知道如何允許 GeoIPupdate 與 Nginx 一起工作,因為我已經運行了 GeoIPupdate。
我嘗試了這個指南:https://github.com/leev/ngx_http_geoip2_module 但現在我得到了這個:
Apr 24 15:25:51 localhost nginx[175588]: nginx: [emerg] unknown directive "if($allowed_country" in /etc/nginx/sites-enabled/default:80
Apr 24 15:25:51 localhost nginx[175588]: nginx: configuration file /etc/nginx/nginx.conf test failed
有問題的配置(在伺服器部分):
if($allowed_country = no) {
return 403;
}
在檢查 Nginx 模組時,我確實看到 50-mod-http-geoip.conf 確實存在並且應該已加載,但寫入 nginx -V 不會輸入該模組。
最有趣的部分是,nginx.conf 確實適用於允許的國家/地區,因為我沒有從中得到任何錯誤。
答案1
我自己用最搞笑、最悲傷的方式解決了這個問題。
請記住,我已經研究這個奇怪的錯誤幾天了,我發現這是因為我添加了一個選項卡,這樣我的強迫症就可以在個人資料中感到滿意。
我複製並粘貼了這個並且它起作用了。 https://gist.github.com/dunderrrrrr/8d3fced1f73de2d70ede38f39c88d215