Search code examples
nginxfastcgiauth-request

nginx auth_request_set does not allow test the variable in the context


I look for a work around for fcgi authorizer and this is how my test config looks:

        location ~* "f4m$" {
                limit_except GET {
                        deny all;
                }
                auth_request /clu;
                auth_request_set $node $upstream_http_server;
# Problem's that $node is always empty for <if> in this context
                proxy_set_header Node $node;
                proxy_pass http://127.0.0.1/group_1tv$request_uri;
        }
        location = /clu {
                internal;

                proxy_pass_request_body off;
                proxy_pass_request_headers off;
                proxy_set_header Content-Length '';

                proxy_pass http://cluster_authorizer$request_uri;
        }
}

it would be all happy and good if I could test the variable $node withing if structure right after the subrequest returns. Unfortunately, it would be always empty, and I have to setup a separate server to tackle it:

server {
        server_name 127.0.0.1;
        location /group_1tv/ {
                if ($request_uri ~ "^/[^/]+(.*)") {}
                if ($http_node) {return http://$http_node$1;}

                proxy_cache hyvd;
                proxy_cache_valid any 1d;
                proxy_pass http://backend_group_1tv/;
        }
}

Unfortunately, again, this works only when $http_node is non-empty and returns 400 (Unknown location) otherwise, and debug log does not explain why:

2014/02/02 18:31:15 [debug] 9602#0: *18 http upstream request: "/hds-live/livepkgr/_definst_/1tv.f4m?r=334"
2014/02/02 18:31:15 [debug] 9602#0: *18 http upstream process header
2014/02/02 18:31:15 [debug] 9602#0: *18 malloc: 09C12AD8:4096
2014/02/02 18:31:15 [debug] 9602#0: *18 recv: fd:12 137 of 4096
2014/02/02 18:31:15 [debug] 9602#0: *18 http proxy status 400 "400 Unknown location"

I've spent 2 full days on this, really need a fresh input...


Solution

  • So I just solved a 400 issue of my own with internal proxy, in that I was setting Content-length to an invalid setting ('') rather than 0.

    Remove this: proxy_set_header Content-Length '';