ngx_http_auth_request自用

server {
listen 80;
server_name www.php12.cn php12.mama1314.com;
root /var/www/shf;
location / {
index index.php index.html;

}

location ~ .php$ {
root /var/www/shf;
fastcgi_pass 127.0.0.1:9000;
fastcgi_index index.php;
include fastcgi_params;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
}
location ~ .txt$ {
auth_request /auth;
}
location = /auth {
add_header PHP_AUTH $request_uri;
proxy_pass http://auth.php12.cn/index.php;
proxy_set_header X-Original-Uri $request_uri;
#proxy_set_header X-Original-Uri $query_string;
proxy_set_header QUERY_STRING $request_uri;
}
access_log /var/log/nginx/www.php12.cn.log;

}

<?php
$query = array();
$para = array();

if(isset($_SERVER['HTTP_X_ORIGINAL_URI']) && !empty($_SERVER['HTTP_X_ORIGINAL_URI']))
{
$para = parse_url($_SERVER['HTTP_X_ORIGINAL_URI']);

if(isset($para['query']) && !empty($para['query']))
{
parse_str($para['query'],$query);
}

}


if(isset($query['key']) && $query['key']=='123') return true;
header('HTTP/1.0 401 Unauth');

原文地址:https://www.cnblogs.com/php12-cn/p/8479211.html