使用Tomcat进行身份验证| NGINX错误301已移动

问题描述 投票:1回答:1

我有一个测试NGINX工作负载,我只限于(任何)内部公司用户使用。用户通过我们组织的内部IAM平台进行身份验证。我正在使用Tomcat Web应用程序对用户进行身份验证,并且尝试使用auth_request配置Nginx来控制访问。我现在不关心授权。

来自:https://docs.nginx.com/nginx/admin-guide/security-controls/configuring-subrequest-authentication/

NGINX向验证该子请求的外部服务器发出HTTP子请求。如果子请求返回2xx响应代码,则允许访问,如果子请求返回401或403,则拒绝访问。

我的T​​omcat应用程序似乎正常工作。我可以手动浏览到应用程序(/ auth),完成身份验证,并收到200个响应代码。

我的NGINX配置有问题。当我浏览到受保护的工作负载(/测试)时,系统会提示我进行身份验证。身份验证成功后,我的Web浏览器将返回“无法连接”(无法访问该站点)错误。如果运行数据包捕获,我可以看到Web服务器返回了移动的错误301资源(在NGINX访问日志中也可以看到)。

我不确定NGINX为什么不承担工作量。错误和访问日志不是很有帮助。还有什么我可以解决的吗? NGINX服务器正在RHEL7上运行。这是测试工作量。我在NGINX中配置了自动索引,因此我相信正确的行为是提供目录结构(我在/ data / www / test /中放置了一些测试文件)。一旦弄清楚了,就需要将auth机制移入生产环境,并开始限制实际的工作量。

我可能是错的,但是我认为这是一个语法问题。任何建议表示赞赏。谢谢。

nginx.conf

# iFor more information on configuration, see:
#   * Official English Documentation: http://nginx.org/en/docs/
#   * Official Russian Documentation: http://nginx.org/ru/docs/

user nginx;
worker_processes auto;
error_log /var/log/nginx/error.log;
pid /run/nginx.pid;

# Load dynamic modules. See /usr/share/doc/nginx/README.dynamic.
# include /usr/share/nginx/modules/*.conf;

events {
    worker_connections 1024;
}

http {
    log_format  main  '$remote_addr - $remote_user [$time_local] "$request" '
                      '$status $body_bytes_sent "$http_referer" '
                      '"$http_user_agent" "$http_x_forwarded_for"';

    access_log  /var/log/nginx/access.log  main;

    sendfile            on;
    tcp_nopush          on;
    tcp_nodelay         on;
    keepalive_timeout   65;
    types_hash_max_size 2048;

    include             /etc/nginx/mime.types;
    default_type        application/octet-stream;

    # Load modular configuration files from the /etc/nginx/conf.d directory.
    # See http://nginx.org/en/docs/ngx_core_module.html#include
    # for more information.
#    include /etc/nginx/conf.d/*.conf;

    server {
        listen       80;
        listen       [::]:80;
        server_name  localhost;
#        root          /data/www;

        # Load configuration files for the default server block.
#       include /etc/nginx/default.d/*.conf;

        location /test {
           root /data/www;
           autoindex on; 
       auth_request  /auth/;
       auth_request_set  $auth_status   $upstream_status;
       }


        location = /auth/ {
            internal;
            proxy_pass              http://0.0.0.0:8080;
            proxy_pass_request_body off;
            proxy_set_header        Content-Length "";
            proxy_set_header        X-Original-URI $request_uri;
        }



        error_page 404 /404.html;
            location = /40x.html {
        }

        error_page 500 502 503 504 /50x.html;
            location = /50x.html {
        }
    }
authentication nginx http-status-code-301
1个回答
0
投票

哇,这是我的错误...

我正在本地计算机上的virtualbox中运行工作负载,并且我的NAT配置中有错字。

多么令人尴尬

[积极地,一位同事建议我将NGINX中的身份验证请求注释掉,以在没有身份验证的情况下测试NGINX。这对于找出问题非常有帮助。

© www.soinside.com 2019 - 2024. All rights reserved.