nginx

问题描述 投票:0回答:0
我正在nginx反向代理后面运行grafana,以解决一个单独使用Grafana无法处理的某些情况。当用户使用JWT(JSON Web令牌)通过URL登录到Grafana并将其导航到Grafana中的其他页面时,就会发生一种这样的情况。如果用户刷新页面,则意外登录并将其重定向到登录屏幕。为了防止这种行为,出于某些其他原因,我在Grafana面前将NGINX与代理登录应用程序一起设置为反向代理。

在这里流动的工作方式:

用户在代理登录应用程序中输入其用户名和密码。
    uupon成功登录,该应用程序生成了带有到期日期的JWT。
  • 应用程序通过向Nginx提出初始get请求来在X-JWT-Assertion标头中发送此JWT。 然后,Application然后将用户重定向到Grafana,用户使用JWT登录将用户登录到Grafana。
  • 我的目标是永久存储JWT令牌,并使用Proxy_redirect将其附加到URL中的后续请求中。这样,即使用户刷新了Grafana的页面,由于URL中存在令牌,会话也不会结束。
  • 挑战在于处理动态令牌。在配置中直接对令牌进行硬编码工作,但是由于令牌随着每个登录而更改,我需要一个更灵活的解决方案。要实现此目的,我正在考虑从初始获取请求中提取X-JWT-Assertion标头的值,然后再重定向到Grafana并以某种方式将其存储。是否可以?如果是这样,我该如何实现?我尝试了一些可能的规则来实现它,但无法成功。如果不可能,我该如何实现最终目标? Feel免费询问您是否需要进一步的帮助或澄清。预先感谢
  • 当前配置是当前的配置(proxy_redirect目前不完整,应在
  • ?auth_token=
  • 之后存储JWT):
  • map $http_upgrade $connection_upgrade { default upgrade; '' close; } upstream grafana { server localhost:32301; } server { listen 80; root /var/www/html; index index.html index.htm index.nginx-debian.html; location / { if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; # # Custom headers and headers various browsers *should* be OK with but aren't # add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,X-JWT-Assertion'; # # Tell client that this pre-flight info is valid for 20 days # add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain; charset=utf-8'; add_header 'Content-Length' 0; return 204; } if ($request_method = 'POST') { add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,X-JWT-Assertion' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } if ($request_method = 'GET') { add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,X-JWT-Assertion' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } rewrite ^/(.*) /$1 break; proxy_pass_request_headers on; proxy_set_header X-REAL-IP $remote_addr; proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; proxy_set_header X-Forwarded-Prote $scheme; proxy_set_header Host $http_host; proxy_pass http://grafana; proxy_redirect ~^(/[^\/?]+)(/[^?]+)?(\?)?(.*)$ $1$2?auth_token=&$4; } location /api/live/ { if ($request_method = 'OPTIONS') { add_header 'Access-Control-Allow-Origin' '*'; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS'; # # Custom headers and headers various browsers *should* be OK with but aren't # add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,X-JWT-Assertion'; # # Tell client that this pre-flight info is valid for 20 days # add_header 'Access-Control-Max-Age' 1728000; add_header 'Content-Type' 'text/plain; charset=utf-8'; add_header 'Content-Length' 0; return 204; } if ($request_method = 'POST') { add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,X-JWT-Assertion' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } if ($request_method = 'GET') { add_header 'Access-Control-Allow-Origin' '*' always; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS' always; add_header 'Access-Control-Allow-Headers' 'DNT,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Range,X-JWT-Assertion' always; add_header 'Access-Control-Expose-Headers' 'Content-Length,Content-Range' always; } rewrite ^/(.*) /$1 break; proxy_http_version 1.1; proxy_set_header Upgrade $http_upgrade; proxy_set_header Connection $connection_upgrade; proxy_set_header Host $http_host; proxy_set_header Cookie $http_cookie; proxy_pass http://grafana/; } }

最终有什么配置?

nginx jwt nginx-reverse-proxy nginx-config
最新问题
© www.soinside.com 2019 - 2025. All rights reserved.