# Auth\_request and auth\_request\_set confusion

**URL:** <https://www.ruby-forum.com/t/auth-request-and-auth-request-set-confusion/228431>\
**Category:** NGINX\
**Created:** [April 22, 2013, 12:24pm UTC](https://www.ruby-forum.com/t/auth-request-and-auth-request-set-confusion/228431 "2013-04-22T12:24:34Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Dale\_Gallagher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/45deac/32.png) [@Dale\_Gallagher](https://www.ruby-forum.com/u/Dale_Gallagher)\
**Post date:** [April 22, 2013, 12:24pm UTC](https://www.ruby-forum.com/t/auth-request-and-auth-request-set-confusion/228431/1 "2013-04-22T12:24:34Z")

</div>

Hi

I’d appreciate it if someone could enlighten me as to why the following  
isn’t working as expected. I’m trying to make the proxying to php  
dynamic -  
in other words, depending on the authenticated user, requests will be  
proxied to that user’s PHP socket.

Both the login and auth locations are proxied to a Perl Dancer app.

Here’s the auth app’s /auth route:

get ‘/auth’ =\> sub {  
if (session(‘user’) && session(‘time’)) {  
my $time\_now = time;  
if ($time\_now - session(‘time’) \< config-\>{‘session\_timeout’}) {  
session ‘time’ =\> $time\_now;  
header ‘X-Auth-User’ =\> session(‘user’);  
status ‘ok’;  
}  
else {  
header ‘X-Error-Page’ =\> ‘/login/session\_expired’;  
status ‘forbidden’;  
}  
}  
else {  
header ‘X-Error-Page’ =\> ‘/login/not\_authorised’;  
status ‘forbidden’;  
}  
};

nginx.conf snippet:

location /login {  
expires -1;  
proxy\_set\_header Host $host;  
proxy\_pass [http://127.0.0.1:3000](http://127.0.0.1:3000);  
proxy\_redirect http://$host https://$host;  
}

location /auth {  
internal;  
expires -1;  
proxy\_set\_header Host $host;  
proxy\_pass [http://127.0.0.1:3001](http://127.0.0.1:3001);  
proxy\_pass\_request\_body off;  
proxy\_redirect http://$host https://$host;  
proxy\_set\_header Content-Length “”;  
}

location /protected {  
error\_page 401 403 $error\_page;  
expires -1;  
set $auth\_user = ‘none’;  
auth\_request /auth;  
auth\_request\_set $error\_page $upstream\_http\_x\_error\_page;  
auth\_request\_set $auth\_user $upstream\_http\_x\_auth\_user;

```
location ~* \.php {
  fastcgi_pass unix:/srv/web/$auth_user/sock/php-5.3.22.sock;
  fastcgi_index index.php;
  fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
  fastcgi_param FILES_ROOT /srv/web/$auth_user/site;
  include fastcgi_params;
}

```

}

The error\_page works, when the Dancer app returns forbidden, but no  
matter  
what I’ve tried to use the X-Auth\_User header on the /auth app returning  
200, I can’t seem to coax nginx into passing it onto anything, be it a  
rewrite, or the above listed .php location stanza.

Any pointers would be appreciated.

Thanks  
Dale

---

<div class="post-metadata">

**Author:** ![Dale\_Gallagher](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/45deac/32.png) [@Dale\_Gallagher](https://www.ruby-forum.com/u/Dale_Gallagher)\
**Post date:** [April 22, 2013, 11:02pm UTC](https://www.ruby-forum.com/t/auth-request-and-auth-request-set-confusion/228431/2 "2013-04-22T23:02:36Z")

</div>

Hello!

On Mon, Apr 22, 2013 at 12:23:59PM +0200, Dale Gallagher wrote:

> ```
> status 'forbidden';
> 
> ```
> 
> location /login {  
> proxy\_pass [http://127.0.0.1:3001](http://127.0.0.1:3001);  
> auth\_request\_set $error\_page $upstream\_http\_x\_error\_page;
> 
> The error\_page works, when the Dancer app returns forbidden, but no matter  
> what I’ve tried to use the X-Auth\_User header on the /auth app returning  
> 200, I can’t seem to coax nginx into passing it onto anything, be it a  
> rewrite, or the above listed .php location stanza.
> 
> Any pointers would be appreciated.

Could you please show debug log?

See [A debugging log](http://nginx.org/en/docs/debugging_log.html) for more  
information.

–  
Maxim D.

> **[nginx: donation](http://nginx.org/en/donation.html)**
