SO , Google, , , . Kubernetes, .
Kubernetes, Django, , , , :
, , OP, DRF http
, API https
. , API- , Django REST Framework (DRF), API. , , DRF, http
, .
:
- Kuberenetes Nginx Ingress Controller ( SSL letsencrypt)
- Django
- Gunicorn Django
settings.py
nginx.conf
. , , : kuberctl get pods -n <namespace of your ingress controller>
, , kubectl exec -it -n ingress_controller_namespace ingress_controller_pod_name cat /etc/nginx/nginx.conf > nginx.conf
.nginx.conf
, , proxy_set_header X-Forwarded-Proto $scheme;
location
, , X-Forwarded-Proto
. Kubernetes nginx ( ) .- Gunicorn. :
--forwarded-allow-ips="*"
gunicorn, , IP- nginx, , gunicorn , gunicorn , , gunicorn django_server.wsgi:application --forwarded-allow-ips="*" --workers=${PROPER_WORKER_NUM} --log-level info --bind 0.0.0.0:8001
. 4 , workers=4
, , . --log-level info
, . - Django
SECURE_PROXY_SSL_HEADER = ('HTTP_X_FORWARDED_PROTO', 'https')
settings.py
, . , HTTP_
nginx X-Forwarded-Proto
. , WSGI , . , HTTP_X_FORWARDED_PROTO
"https"
, Django . , , request.is_secure == True
, request.build_absolute_uri(None) == 'https://...'
, , Django REST Framework https
! ( API https
)
, . DRF https - . , , , , - DRF http
. , :
Django, print()
, DEBUG=True
, html-, , SSL.
request.is_secure()
: DRF http
, , False
.request.META
, . HTTP_X_FORWARDED_PROTO
? ?- , -:
HTTP_X_FORWARDED_PROTO
http,https
, , - , , , proxy_set_header
, ! K8 , , location-snippet
, proxy_set_header X-Forwarded-Proto $scheme;
. , DRF https
, . , , proxy_set_header
"" . , , .