postgresql – 在NGINX中使用Postgres Basic Auth将查询结果添加到Proxy HTTP Header

postgresql – 在NGINX中使用Postgres Basic Auth将查询结果添加到Proxy HTTP Header,第1张

概述我们正在尝试使用ngx_postgres模块通过NGINX进行基本身份验证.我们想从查询结果对中检索一个值并将其添加到HTTP标头,然后将其代理到另一个服务器. 我们已成功通过postgres进行身份验证,但问题是将结果对传递给代理.我们目前使用的代码如下: location = /test_auth { internal; postgres_es 我们正在尝试使用ngx_postgres模块通过Nginx进行基本身份验证.我们想从查询结果对中检索一个值并将其添加到http标头,然后将其代理到另一个服务器.

我们已成功通过postgres进行身份验证,但问题是将结果对传递给代理.我们目前使用的代码如下:

location = /test_auth {            internal;            postgres_escape $user $remote_user;            postgres_escape $pass $remote_passwd;            postgres_pass geo_database;            postgres_query "select user_name,contract_ID,access_token from schema_name.table_name where user_name=$user and password=md5($pass);";            postgres_rewrite no_rows 401;            more_set_headers -s 401 'WWW-Authenticate: Basic realm="Restricted"';            postgres_output none;            postgres_set $query_val 0 0 required;    }    location /test/ {           auth_request /test_auth;           proxy_pass      http://back_end_server/public-dev/;           proxy_set_header test $query_val;           proxy_redirect http://back_end_server/public-dev/ http://example_domain.com/;    }

这是我们尝试过的许多不同事物的一部分.此示例中的问题是query_val似乎在子请求中被销毁.当postgres调用不在子请求中时,我们成功地能够检索查询结果对,但这会禁用我们的身份验证.

我们还在主要位置尝试了一个简单的查询,然后将这些数据代理到另一个位置,但它失败了.如果我们将查询结果对定向到像index.HTML文件这样的本地资源,它将被正确地添加到头文件中,但是一旦我们尝试将它添加到http头并将其发送到代理,它就不会更长的存在.

关于这个问题的任何建议将不胜感激.

[更新]我花了一整天阅读我正在使用的模块,我真的认为这是模块的阶段顺序的问题.我感觉代理重写是在postgres身份验证子请求实际返回结果之前发生的.我会继续调查.任何帮助仍然受到赞赏.

该问题的解决方案最终使用auth_request_set函数在适当的Nginx阶段期间提取正确的值.以下代码是可行的解决方案.
location = /test_auth {        internal;        postgres_escape $user $remote_user;        postgres_escape $pass $remote_passwd;        postgres_pass geo_database;        postgres_query "select user_name,access_token from schema_name.table_name where user_name=$user and password=md5($pass);";        postgres_rewrite no_rows 401;        more_set_headers -s 401 'WWW-Authenticate: Basic realm="Restricted"';        postgres_output none;        postgres_set $query_val 0 0 required;}location /test/ {       auth_request /test_auth;       auth_request_set $proper_query_val $query_val;       proxy_pass      http://back_end_server/public-dev/;       proxy_set_header test $proper_query_val;       proxy_redirect http://back_end_server/public-dev/ http://example_domain.com/;}
总结

以上是内存溢出为你收集整理的postgresql – 在NGINX中使用Postgres Basic Auth将查询结果添加到Proxy HTTP Header全部内容,希望文章能够帮你解决postgresql – 在NGINX中使用Postgres Basic Auth将查询结果添加到Proxy HTTP Header所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/sjk/1168778.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-02
下一篇 2022-06-02

发表评论

登录后才能评论

评论列表(0条)

保存