nginx http auth module query

Maxim Dounin mdounin at mdounin.ru
Fri Feb 17 14:18:43 UTC 2012


Hello!

On Fri, Feb 17, 2012 at 08:30:33AM -0500, karanj wrote:

> It doesn't work for me. 
> 
> I have 3 files running under HipHop -
> 1) /tf/test.php - This file sets the session variable -
> $_SESSION['X-ErrorPage']='/tf2/test.php';
> and then sends header("HTTP/1.1 401 Unauthorized");
> 2) /tf2/test2.php - This prints "It works"
> 3) /tf2/test.php - This prints "Error Page"
> 
> My config looks like this -
> The output on running http://112.11.23.221:8080/tf2/test2.php should be
> - "Error Page". But this is not happening.
> 
> The nginx error logs shows the following -
> 
> 2012/02/17 18:52:45 [error] 10103#0: *4 the rewritten URI has a zero
> length, client: 122.179.93.88, server: 112.11.23.221, request: "GET
> /tf2/test2.php HTTP/1.1", host: "112.11.23.221:8080"
> 
> server {
>         listen       8080;
>         server_name  112.11.23.221;
> 
>         location / {
>                 auth_request /tf/test.php;
>                 proxy_pass      http://127.0.0.1:4247;
>                 error_page  401 = /40x.html;
>         }
>         location /tf/test.php{
>                 proxy_pass      http://127.0.0.1:4247;
>         }
> 
>         location = /40x.html {
>                 auth_request_set $err $upstream_http_x_errorpage;
>                 rewrite /40x.html $err;
>                 proxy_pass      http://127.0.0.1:4247;
>         }
>     }

You have to use auth_request_set in the same location with 
auth_request directive.

    location / {
        auth_request /tf/test.php;
        auth_request_set $err $upstream_http_x_errorpage;
        ...
    }

    ...

Maxim Dounin



More information about the nginx mailing list