Forum: NGINX Pass parameters though auth_request directive?

2974d09ac2541e892966b762aad84943?d=identicon&s=25 engenex (Guest)
on 2013-11-18 09:40
(Received via mailing list)
Hi,

I am try to implement a simple auth system using nginx,
nginx-auth-request-module and php-fpm.

I want to do the following:
User requests http://myserver.com/content/file1.zip?key=12345

location /content {
  auth_request /auth_http.php;
  # do some logic in auth_http.php then
  # depending on response from auth_http.php drop the connection or
allow
downloading
{

I can't get the parameters from the request URI to my auth_http.php
using
the auth_request directive.
My simple auth_http.php to check for the key param:

<?php
  $key = $_GET['key'];
  error_log("key is $key \n");  ?>

This shows error in php log:
PHP Notice:  Undefined index: key in /usr/local/nginx/html/auth_http.php

I also checked the sizeof $_GET and it is 0.  Can someone help me
please?

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,244760,244760#msg-244760
A8108a0961c6087c43cda32c8616dcba?d=identicon&s=25 Maxim Dounin (Guest)
on 2013-11-18 13:30
(Received via mailing list)
Hello!

On Mon, Nov 18, 2013 at 03:40:16AM -0500, engenex wrote:

>   # do some logic in auth_http.php then
>   error_log("key is $key \n");  ?>
>
> This shows error in php log:
> PHP Notice:  Undefined index: key in /usr/local/nginx/html/auth_http.php
>
> I also checked the sizeof $_GET and it is 0.  Can someone help me please?

This is expected - as auth request is to "/auth_http.php", and
there is no query string in the subrequest.  If you want to check
original request arguments, you have to check them explicitly.

Assuming default fastcgi_param configuration and php, original
request URI (with original query string aka request arguments)
should be available via $_SERVER['REQUEST_URI'].

--
Maxim Dounin
http://nginx.org/en/donation.html
2974d09ac2541e892966b762aad84943?d=identicon&s=25 engenex (Guest)
on 2013-11-18 16:35
(Received via mailing list)
Hi Maxim!

Your solution worked.  Thanks for the fast response.

I was able to access the original params through the
$_SERVER['REQUEST_URI']
php array as you said.  I didn't even have to change my conf.

God bless you.  I spent the better part of the last 24 hours trying to
figure this one out.
I should have paid closer attention to my nginx error.log...  the answer
was
right there in front of me ;)

[debug] 15544#0: *15 fastcgi param: "REQUEST_URI:
/content/file3.zip?psk=abracadabra"

Posted at Nginx Forum:
http://forum.nginx.org/read.php?2,244760,244778#msg-244778
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.