我正在为反向代理服务器编写一个Nginx conf文件。
我的一个位置受安全链接模块(http_secure_link_module)保护。
但我需要的是一个条件secure_link指令。
如下所示:如果URI包含正确的令牌,我将添加一个像status=is_authorized这样的set -Cookie头,然后如果用户没有设置状态cookie,则再次保护链接。
location / {
if ($cookie_STATUS = "IS_AUTHORIZED") {
// if possible cancel secure_link for authorized (with cookie) users.
}
secure_link $arg_token;
secure_link_md5 "MD5_SECRET_PARAMETERS";
set $token $arg_token;
if ($secure_link = "") {
return 403;
}
if ($secure_link = "0") {
return 410;
}
# Set Cokie
add_header Set-Cookie STATUS=IS_AUTHORIZED;
add_header Set-Cookie TOKEN=$arg_token;
# Rewrite rules
include /usr/local/nginx/conf/rewrite_rules.conf;
# Set Cache
proxy_cache confluence_cache;
include /usr/local/nginx/conf/cache.conf;
# include /etc/nginx/shared/google_analytics.conf;
# Confluence Authentication
proxy_set_header Authorization "Basic BASE_64_HASH";
proxy_pass PROXY_URL;
}有人能帮我做到这一点吗?基本上,我只想保护那些没有将状态cookie设置为IS_AUTHORIZED的用户的链接。或者仅在第一次访问页面时使用secure_link。
谢谢你们。
发布于 2017-06-29 05:24:29
我已经设法在我的配置文件中使用了另一个变量。
# if token is invalid nginx set $secure_link as empty string
if ($secure_link = "") {
set $is_allowed 'forbidden';
}
# if expiration time is gone nginx set $secure_link as 0
if ($secure_link = "0") {
set $is_allowed 'gone';
}
# if status cookie is set $is_allowed get 'authorized' as value
if ($cookie_STATUS = "IS_AUTHORIZED") {
set $is_allowed 'authorized';
}
# return 403 if $is_allowed = forbidden
if ($is_allowed = 'forbidden') {
return 403;
}
# return 410 if $is_allowed = gone
if ($is_allowed = 'gone') {
return 410;
}然后,它正常地设置代理,以及其他事情。
https://stackoverflow.com/questions/44789930
复制相似问题