Nginx 中的请求顺序
Requests sequence in Nginx
我有一个场景,服务器需要在实际请求之前进行授权请求。因此,一个请求由 2 个不同的服务提供服务。
Nginx的location需要Auth-Service处理,如果响应状态为200 OK,则请求转发给Feature-Service。否则,如果响应状态为401,则应将此状态回复给前端。
upstream auth_service {
server localhost:8180;
}
upstream feature_service {
server localhost:8080;
}
location /authAndDo {
# suggest here
}
nginscript 中的代码片段也可以。
一般来说,这样的网络服务器是不可能的。 401 是前端的响应加上 HTTP WWW-Authenticate 响应 header。根据需要开发Web应用程序或编辑401文件。 HTTP 401 has RFC specification. Users, browsers should understand the message. Nginx doc described how 401 will be handled.
Nginx 社区版的 auth_request
只会处理子请求 returns HTTP 200,否则对于 401 默认不会重定向超过 401,其他 header 不会处理响应以保护应用程序和用户。 Nginx 社区版甚至不支持 HTTP/2 的所有功能。它可能会变得更糟。
Apache2 网络服务器具有完整的 HTTP/2 支持和 custom 401 location in auth module,并且仅适用于少数浏览器。很少有浏览器允许 Apache2 完美地做到这一点。其他人显示无法加载页面。在 Stack Exchange 网络的各种子域上,人们之前要求 Apache2 使其适用于所有浏览器。
你几乎不能在 Nginx 上重定向:
error_page 401 /401.html;
location ~ (401.html)$ {
alias /usr/share/nginx/html/;
}
另一种方法可能是对另一台服务器使用反向代理 like peoples talking here on Github。我不能保证加载页面失败。
专门为此目的,http://nginx.org/r/auth_request exists through http://nginx.org/docs/http/ngx_http_auth_request_module.html(默认情况下未构建)。
它允许您通过子请求将身份验证放入您想要的任何位置,有效地将身份验证与实际资源分开。
我有一个场景,服务器需要在实际请求之前进行授权请求。因此,一个请求由 2 个不同的服务提供服务。
Nginx的location需要Auth-Service处理,如果响应状态为200 OK,则请求转发给Feature-Service。否则,如果响应状态为401,则应将此状态回复给前端。
upstream auth_service {
server localhost:8180;
}
upstream feature_service {
server localhost:8080;
}
location /authAndDo {
# suggest here
}
nginscript 中的代码片段也可以。
一般来说,这样的网络服务器是不可能的。 401 是前端的响应加上 HTTP WWW-Authenticate 响应 header。根据需要开发Web应用程序或编辑401文件。 HTTP 401 has RFC specification. Users, browsers should understand the message. Nginx doc described how 401 will be handled.
Nginx 社区版的 auth_request
只会处理子请求 returns HTTP 200,否则对于 401 默认不会重定向超过 401,其他 header 不会处理响应以保护应用程序和用户。 Nginx 社区版甚至不支持 HTTP/2 的所有功能。它可能会变得更糟。
Apache2 网络服务器具有完整的 HTTP/2 支持和 custom 401 location in auth module,并且仅适用于少数浏览器。很少有浏览器允许 Apache2 完美地做到这一点。其他人显示无法加载页面。在 Stack Exchange 网络的各种子域上,人们之前要求 Apache2 使其适用于所有浏览器。
你几乎不能在 Nginx 上重定向:
error_page 401 /401.html;
location ~ (401.html)$ {
alias /usr/share/nginx/html/;
}
另一种方法可能是对另一台服务器使用反向代理 like peoples talking here on Github。我不能保证加载页面失败。
专门为此目的,http://nginx.org/r/auth_request exists through http://nginx.org/docs/http/ngx_http_auth_request_module.html(默认情况下未构建)。
它允许您通过子请求将身份验证放入您想要的任何位置,有效地将身份验证与实际资源分开。