我想使用auth_request和oauth2_proxy在成功的身份验证请求时设置标头,然后将其传递给将处理实际请求的下一个代理内联.
我已经设置了NGINX和各种代理来做他们的事情,但是我不确定如何设置来自服务器的标头(图中的AUTH PROXY),我正在使用auth请求,以便将该标头传递给下一个服务器(图中的BACKEND SERVER)
NGINX ---- auth request ----> AUTH PROXY
|
| <--- 201 <------ SUCCESS
|
----> underlying request ----> BACKEND SERVER
Run Code Online (Sandbox Code Playgroud)
我的NGINX配置看起来像
server {
listen 9123;
resolver 10.3.0.2;
resolver_timeout 30;
location / {
auth_request /_auth;
proxy_set_header x-user $http_x_user;
proxy_pass http://backend_server;
}
location = /_auth {
internal;
proxy_pass https://auth;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
}
Run Code Online (Sandbox Code Playgroud)
当我发出实际请求时,我在NGINX调试日志中看到以下内容(这是来自auth服务器的响应的一部分):
2013/10/14 17:46:42 [debug] 31222#0: *4 http proxy header: "Content-Type: text/html; charset=utf-8"
2013/10/14 17:46:42 [debug] …
Run Code Online (Sandbox Code Playgroud) 我已经安装了启用了auth_request模块的nginx,但是当我尝试设置身份验证时,我遇到了问题.我想通过php脚本进行身份验证,当用户向此位置发出请求,然后nginx请求到php文件,如果响应将是2xx,那么如果响应将是4xx则身份验证为true,则身份验证失败.
这就是我现在所做的,它是完美的工作,但我不知道如何传递php文件的参数,如用户名密码,例如:http://example.com/live/index.php? username = test&password = 密码
这是没有这些参数的配置.
location /live {
auth_request /http_auth;
}
location /http_auth {
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
proxy_pass http://127.0.0.1/login.php;
}
Run Code Online (Sandbox Code Playgroud)
谢谢
我想转发实时 HLS 流。我想使用 auth_request 模块。我想通过传递密钥来检查请求是否有效。所以类似:http://domain.com/hls/stream.m3u8 ?key=xxxxxxx
我在 nginx.conf 中有以下设置:
location /hls {
alias /tmp/hls;
auth_request /hls/auth;
}
location /hls/auth {
proxy_pass http://localhost.com:8080/on_play.php;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
Run Code Online (Sandbox Code Playgroud)
现在我需要在http://localhost.com:8080/on_play.php中获取 key=xxxxx 。
我尝试了很多,但似乎没有任何效果。我也尝试过类似的事情:
location /hls {
alias /tmp/hls;
auth_request http://localhost.com:8080/on_play.php?key=$arg_key;
}
Run Code Online (Sandbox Code Playgroud)
但这也行不通。似乎不可能在 on_play.php 中获取关键参数
$_SERVER["REQUEST_URI"] 也不包含参数。
还尝试了以下配置:
我也尝试过类似的方法,但这也不起作用:
location ~ ^/hls/(long|short)/([0-9a-zA-Z]+)\.m3u8 {
alias /tmp/hls/$1/$2.m3u8;
auth_request /hls/auth-play/$1/$2;
}
location ~ ^/hls/auth-play/(long|short)/([0-9a-zA-Z]+) {
proxy_pass http://loclahost.com:8080/on_play.php?app=$1&room=$2;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
Run Code Online (Sandbox Code Playgroud)
但这也行不通。
nginx -V …
我正在使用Nginx(版本1.9.9)作为我的后端服务器的反向代理.它需要根据POST请求的内容执行身份验证/授权.我在auth_request处理程序中读取POST请求正文时遇到问题.这就是我得到的.
Nginx配置(相关部分):
server {
location / {
auth_request /auth-proxy;
proxy_pass http://backend/;
}
location = /auth-proxy {
internal;
proxy_pass http://auth-server/;
proxy_pass_request_body on;
proxy_no_cache "1";
}
}
Run Code Online (Sandbox Code Playgroud)
在我的auth-server代码(Python 2.7)中,我尝试读取请求体,如下所示:
class AuthHandler(BaseHTTPServer.BaseHTTPRequestHandler):
def get_request_body(self):
content_len = int(self.headers.getheader('content-length', 0))
content = self.rfile.read(content_len)
return content
Run Code Online (Sandbox Code Playgroud)
我打印出content_len并且它具有正确的值.但是,self.rfile.read()将挂起.最终它会超时并返回"[Errno 32] Broken pipe".
这是我将测试数据发布到服务器的方式:
$ curl --data '12345678' localhost:1234
Run Code Online (Sandbox Code Playgroud)
上面的命令也会挂起并最终超时并打印"Closing connection 0".
我正在做什么明显的错误?
非常感谢!
我正在研究OAuth
两个服务器之间的安全性应用程序.我有一个OAuth Server
和一个Resource Server
.该Resource Server
有一个单一的.war
部署包含4 APIs
.
OAuth server
具有验证的一个access token
,是由一个通过API
从相同(4:1) .war
.OAuth server
具有保持hit count
特定accessToken
特定API
.如果hit count
超过配置hits
,OAuth server
则会抛出403:禁止.API
在.war
必须首先验证accessToken
从OAuth server
,如果它有效,然后继续提供响应.如果a .war
有单个,API
那么我可以简单地让两个服务器使用a进行通信webHook
,下面是执行它的代码.
在资源服务器端:
我对不同API的网址是:
localhost:8080/API/API1
localhost:8080/API/API2
下面的代码路径的任何要求,如果他们有/API/anything
朝spring security filters
spring-security spring-boot spring-security-oauth2 auth-request spring-oauth2
我想让我的nginx代理仅在客户端尚未通过身份验证时才执行身份验证的子请求。条件部分是我被困住的地方。如何设计配置,以便每个会话仅对客户端进行一次身份验证?
我能够成功执行对Apache的auth_request并拉回要传递给后端的标头,但这在每个请求中都会发生,并且代价很高。
在此处的示例中,我的目标是仅在“ Authorization”标头丢失或为空或包含令牌的cookie时才执行auth_request
# DEFAULT BACKEND
location / {
proxy_pass_request_body off;
if ($http_authorization ~* '')
{
rewrite ^(.*)$ /__login;
}
if ($user !~* "([aa-zZ]+)@example.com")
{
}
if ($http_cookie !~* "(auth_cookie=([aa-zZ]+)@example.com)")
{
add_header Set-Cookie "auth_cookie=$user;domain=.example.com;Max-Age=3000";
}
proxy_pass_header x-webauth-user;
proxy_pass_header Set-Cookie;
proxy_pass http://example.com:6762/;
}
Run Code Online (Sandbox Code Playgroud)
位置/ __ login {内部;
auth_request /auth;
auth_request_set $user $upstream_http_x_webauth_user;
set $xuser $user;
add_header Auth-User $user;
proxy_set_header User-Name $user;
proxy_set_header Authorization $http_authorization;
#proxy_pass_header x-webauth-user;
#proxy_pass_header Set-Cookie;
proxy_pass http://example:6762/;
access_log /etc/nginx/login_debug.log;
}
location = /auth{
internal;
proxy_pass http://example.com:81/;
proxy_pass_request_body …
Run Code Online (Sandbox Code Playgroud) 我使用 auth_request 模块(http://nginx.org/en/docs/http/ngx_http_auth_request_module.html)。我的 nginx 配置:
auth_request /auth;
auth_request_set $backend_status $upstream_status;
location / {
proxy_pass http://unicorn;
error_page 401 @auth;
}
location = /auth {
internal;
proxy_pass https://proxy_pass_url;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
}
location @auth {
if ($backend_status = "401") {
return 302 https://proxy_pass_url/login? origin=$scheme://$http_host$request_uri;
}
}
Run Code Online (Sandbox Code Playgroud)
但我的重定向不起作用。我的配置出了什么问题?
我想从我的请求标头字段授权中缓存令牌。
Authorization : Bearer abcdefghijklmnopqrstuvwxyz
我的目标是,我不必验证验证服务器上的每个请求。如果 Authorization-Token 被缓存(并且有效),那么请求应该在没有验证的情况下调用 API。
location /main {
auth_request /auth;
proxy_ignore_headers Cache-Control;
proxy_pass http://API;
proxy_http_version 1.1;
}
location /auth {
internal;
proxy_cache my_cache;
proxy_ignore_headers Cache-Control;
proxy_cache_key "$http_authorization";
proxy_pass https://validationserver;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
}
Run Code Online (Sandbox Code Playgroud)
这是我的设置,但这不起作用。
我希望你能帮助我。
你好!
我有下面的 nginx conf 文件将所有请求(默认情况下)重定向到 /auth (我的服务),然后返回响应标头(foo_id)。该标头将被转发到用户触发的原始请求 URI。下面的内容与 nginx 一起正常工作。...
location /
{
auth_request /auth;
auth_request_set $foo_id $upstream_http_foo_id;
proxy_pass $request_uri
proxy_set_header X-foo-Token $foo_id;
root html;
index index.html index.htm;
}
location /auth
{
internal;
proxy_pass https://myhost/myservice;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
Run Code Online (Sandbox Code Playgroud)
但我需要实现上述用例所需的相应入口规则/注释。我无法获得相应的身份验证/代理通行证相关注释。请帮忙。
我可以创建一个位置,该位置可以被 nginx 配置中的任何其他位置访问,但不能从外部直接访问吗?
我可以使用拒绝指令,但它也会拒绝访问 nginx 配置中定义的位置。
这是我的配置 -
server {
listen *:80;
server_name 127.0.0.1;
location = /auth {
set $query '';
if ($request_uri ~* "[^\?]+\?(.*)$") {
set $query $1;
}
# add_header X-debug-message "Parameters being passed $is_args$args" always;
proxy_pass http://127.0.0.1:8080/auth?$query;
}
location /kibana/ {
rewrite ^/kibana/(.*) /$1 break;
proxy_pass http://127.0.0.1:5601;
proxy_http_version 1.1;
proxy_set_header Upgrade $http_upgrade;
proxy_set_header Connection 'upgrade';
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $remote_addr;
proxy_set_header X-Real-IP $remote_addr;
proxy_cache_bypass $http_upgrade;
auth_request /auth;
}
location ~ (/app/|/app/kibana|/bundles/|/kibana4|/status|/plugins|/ui/|/api/|/monitoring/|/elasticsearch/) {
internal;
proxy_pass http://127.0.0.1:5601;
proxy_http_version …
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用auth_request模块来检查是否允许用户访问某个文件。用户在 发布请求/my/download/uri/<File ID>
。我希望将授权请求发布在auth_service:9999/files/<File ID>
。我的配置的相关部分如下:
location /my/download/uri {
auth_request /auth/files/$uri;
alias /my/file/directory;
}
location /auth {
internal;
proxy_pass http://auth_service:9999/;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
}
Run Code Online (Sandbox Code Playgroud)
该请求由授权服务接收,但实际上是 /files/$uri
;该变量未放置。我尝试set
先通过变量准备好 URI,但没有成功。如何让 nginx 正确定向授权请求?
(注意:我知道我可以通过 将原始请求包含在授权请求的标头中X-Original-URI
。但是,这意味着我必须在授权服务器上对完整 URI 进行额外处理才能获取相关数据,我宁愿这样做如果有办法将授权请求发送到正确的 URI,则不会这样做。)
auth-request ×11
nginx ×10
php ×2
caching ×1
nginx-config ×1
proxy ×1
redirect ×1
spring-boot ×1
token ×1