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');

 

posted @   狂猫  阅读(215)  评论(0编辑  收藏  举报
编辑推荐:
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
· Linux系列:如何用heaptrack跟踪.NET程序的非托管内存泄露
阅读排行:
· TypeScript + Deepseek 打造卜卦网站:技术与玄学的结合
· Manus的开源复刻OpenManus初探
· AI 智能体引爆开源社区「GitHub 热点速览」
· 三行代码完成国际化适配,妙~啊~
· .NET Core 中如何实现缓存的预热?
点击右上角即可分享
微信分享提示