S
S
Sergey2015-09-26 04:36:42
PHP
Sergey, 2015-09-26 04:36:42

How to use Nginx auth_request?

I read examples on the Internet and NGINX docs about this, but I still can’t implement the authorization system on the channel ...
In location /pub #nginx-push-stream
I insert
auth_request / auth;
And I make another location:

location =  /auth {
            internal;
            proxy_pass http://www.mysite.ru/ajax_post?act=auth;
            proxy_pass_request_body off;
            proxy_set_header Content-Length "";
            proxy_set_header X-Original-URI $request_uri;

    }

In PHP I write the following:
function auth(){
  if($user_id > 0){
    header('Status: 200 OK', true, 200);
    	exit;
  } else {
    header('Status: 403 Forbidden', true, 403);
    	exit;
  }
}

What's wrong? Maybe I didn’t understand something ... Because with such a conf, messages are not written at all even from authorized ones ... Tell me, please!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey Nikiforov, 2015-09-26
@goodwin74

Try to remove internal;
the rest seems to be ok. If it doesn't work, look at the access logs.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question