我試圖創建一個基於查詢字符串的URL PARAM一個NGINX重定向。基本上具有:nginx的位置和Django的權威性
http://localhost/redirect/?url=https://www.google.it/search?dcr=0&source=hp&q=django&oq=django
和
location /redirect/ {
proxy_cache STATIC;
# cache status code 200 responses for 10 minutes
proxy_cache_valid 200 1d;
proxy_cache_revalidate on;
proxy_cache_min_uses 3;
# use the cache if there's a error on app server or it's updating from another request
proxy_cache_use_stale error timeout updating http_500 http_502 http_503 http_504;
# don't let two requests try to populate the cache at the same time
proxy_cache_lock on;
# Strip out query param "timestamp"
if ($args ~ (.*)×tamp=[^&]*(.*)) {
set $args $1$2;
}
return 302 $arg_url$args;
}
現在,只有Django的認證的用戶(JWT /曲奇)可以使用/redirect?url=
終點,因此是有可能實現的會話/ cookie檢查而不打開代表整個世界?
無論如何,我可以在Django級別(https://github.com/mjumbewu/django-proxy/blob/master/proxy/views.py)做到這一點,但我認爲它在NGINX級別上運行速度更快,計算成本更低。
感謝,
d
有點不清楚您的查詢,所以你要'/ redirect'只可用於身份驗證的用戶? –
是的,我要修改它。 – Daviddd
我認爲你可以使用'auth_request'來做到這一點。看到這個https://nginx.org/en/docs/http/ngx_http_auth_request_module.html#auth_request和https://www.nginx.com/resources/admin-guide/restricting-access-auth-request/ –