برنامه نویسی
محدود کردن دسترسی بر اساس موقعیت جغرافیایی با استفاده از NGINX با Helm

این مقاله توضیح میدهد که چگونه میتوانید توزیع محتوا را به یک کشور خاص از سرویسهای Kubernetes خود محدود کنید
خوشه، با استفاده از ماژول پویا GeoIP2.
پیش نیازها
- با استفاده از Helm، NGINX Ingress Controller را در خوشه Kubernetes خود نصب کنید.
دریافت پایگاه داده GeoLite2 از MaxMind
این MaxMind شرکت ارائه می کند GeoLite2 رایگان
پایگاه داده های موقعیت جغرافیایی IP شما باید یک حساب کاربری در وب سایت MaxMind ایجاد کنید و a ایجاد کنید کلید مجوز.
پیکربندی کنترل کننده ورودی NGINX
نمودار هلم NGINX را با مقادیر زیر نادیده بگیرید:
controller:
# Maxmind license key to download GeoLite2 Databases
maxmindLicenseKey: ""
extraArgs:
# GeoLite2 Databases to download (default "GeoLite2-City,GeoLite2-ASN")
maxmind-edition-ids: GeoLite2-Country
service:
# Preserve source IP...
externalTrafficPolicy: Local
# ...Which is only supported if we enable the v2 proxy protocol for the OVH load balancer (specific to OVH Cloud provider)
annotations:
service.beta.kubernetes.io/ovh-loadbalancer-proxy-protocol: "v2"
config:
use-proxy-protocol: "true"
# Enable Ingress to parse and add -snippet annotations/directives
allow-snippet-annotations: "true"
# Enable geoip2 module
use-geoip: "false"
use-geoip2: "true"
# Configure access by geographical location.
# Here, we map ISO 3166 country codes to the custom variable allowed_country.
# Map directives are only allowed at Ingress Controller level.
http-snippet: |
map $geoip2_country_code $allowed_country {
default no;
FR yes;
}
نمونه ورود
یک مثال حداقل منبع ورودی:
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
name: minimal-ingress
annotations:
nginx.ingress.kubernetes.io/rewrite-target: /
# Restrict access by geographical location
nginx.ingress.kubernetes.io/server-snippet: |
if ($allowed_country = no) {
return 451;
}
spec:
ingressClassName: nginx-example
rules:
- http:
paths:
- path: /testpath
pathType: Prefix
backend:
service:
name: test
port:
number: 80
توجه داشته باشید: کد وضعیت HTTP 451 به عنوان مرجع رمان انتخاب شد
“فارنهایت 451”.
منابع