在我的位置,我设置了这个代码:
set $clientapikey "<my client api key>"; add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT'; proxy_set_header X-Real-IP $remote_addr; proxy_set_header X-NginX-Proxy true; proxy_pass http://$api_route/$path$is_args$args; proxy_set_header X-Forwarded-For $remote_addr; proxy_set_header X-Forwarded-Host $remote_addr; proxy_set_header clientapikey $clientapikey; proxy_ssl_session_reuse off; proxy_set_header Host $http_host; proxy_redirect off;
我想logging由proxy_pass发送到远程URL的头,以查看我的密钥是否实际发送到远端服务器( $api_route )。
我试图login:
log_format 'Sent-Headers: "clientapikey: ' '$upstream_http_clientapikey ' '$http_clientapikey" ';
但$ upstream_http_clientapikey和$ http_clientapikey也似乎让我访问正确的发送头。
我认为你唯一能做的就是logging$clientapikey 。 但是这将会有一个众所周知的价值,所以我不期望它在debugging这个问题上有太多的用处。 在这种情况下,我会在nginx服务器上首先使用curl来检查API服务器头格式。 我敢打赌,API服务器实际上期待HTTP Auth头。
curl -v -h 'clientapikey: my client api key' -X POST http://apiendpoint
nb另外,使用http://调用api端点应该是不鼓励的,因为它允许任何人读取你的客户端API密钥。