【发布时间】:2018-03-07 09:21:52
【问题描述】:
我正在尝试根据查询字符串中的 URL 参数创建 NGINX 重定向。基本上有:
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/Cookie) 可以使用/redirect?url= 端点,因此是否可以在不向全世界打开代理的情况下实现会话/cookie 检查?
无论如何,我可以在 Django 级别 (https://github.com/mjumbewu/django-proxy/blob/master/proxy/views.py) 做到这一点,但我认为在 NGINX 级别它更快且计算成本更低。
谢谢,
D
【问题讨论】:
-
您的查询有点不清楚,所以您希望
/redirect仅对经过身份验证的用户可用? -
是的,我要修改它。
-
我认为您可以为此使用
auth_request。看到这个nginx.org/en/docs/http/… 和nginx.com/resources/admin-guide/restricting-access-auth-request
标签: django nginx nginx-location