11.3.4.3. API 게이트웨이가 3scale를 올바르게 호출합니까?
문제 해결을 위해 API 게이트웨이가 3scale에 수행하는 요청을 확인하려면 nginx.conf의 3scale authrep 위치(API Key 및 App\_id 인증 모드의 경우
/threescale_authrep )에만 다음 스니펫을 추가할 수 있습니다.
body_filter_by_lua_block{
if ngx.req.get_headers()["X-3scale-debug"] == ngx.var.provider_key then
local resp = ""
ngx.ctx.buffered = (ngx.ctx.buffered or "") .. string.sub(ngx.arg[1], 1, 1000)
if ngx.arg[2] then
resp = ngx.ctx.buffered
end
ngx.log(0, ngx.req.raw_header())
ngx.log(0, resp)
end
}
이 코드 조각은 X-3scale-debug 헤더 가 전송되면 nginx error.log에 다음과 같은 추가 로깅을 추가합니다(예: curl -v -H 'X-3scale-debug): YOUR_PROVIDER_KEY' -X GET "https://726e3b99.ngrok.com/api/contacts.json?access_token=7c6f24f5"
이렇게 하면 다음 로그 항목이 생성됩니다.
2016/05/05 14:24:33 [] 7238#0: *57 [lua] body_filter_by_lua:7: GET /api/contacts.json?access_token=7c6f24f5 HTTP/1.1
Host: 726e3b99.ngrok.io
User-Agent: curl/7.43.0
Accept: */*
X-Forwarded-Proto: https
X-Forwarded-For: 2.139.235.79
while sending to client, client: 127.0.0.1, server: pili-virtualbox, request: "GET /api/contacts.json?access_token=7c6f24f5 HTTP/1.1", subrequest: "/threescale_authrep", upstream: "https://54.83.62.94:443/transactions/oauth_authrep.xml?provider_key=REDACTED&service_id=REDACTED&usage[hits]=1&access_token=7c6f24f5", host: "726e3b99.ngrok.io"
2016/05/05 14:24:33 [] 7238#0: *57 [lua] body_filter_by_lua:8: <?xml version="1.0" encoding="UTF-8"?><error code="access_token_invalid">access_token "7c6f24f5" is invalid: expired or never defined</error> while sending to client, client: 127.0.0.1, server: pili-virtualbox, request: "GET /api/contacts.json?access_token=7c6f24f5 HTTP/1.1", subrequest: "/threescale_authrep", upstream: "https://54.83.62.94:443/transactions/oauth_authrep.xml?provider_key=REDACTED&service_id=REDACTED&usage[hits]=1&access_token=7c6f24f5", host: "726e3b99.ngrok.io"
첫 번째 항목(2016/05 14:24:33 [] 7238#0: *57 [lua] body_filter_by_lua:7:)은 3scale로 전송된 요청 헤더를 출력합니다. Host, User-Agent, accept, X-Forwarded-Proto 및 X-Forwarded-Forwarded.
두 번째 항목(2016/05/05 14:24:33 [] 7238#0: *57 [lua] body_filter_by_lua:8:)은 3scale의 응답을 출력합니다. 이 경우 <error code="access_token_invalid">access_token "7c6f24f is invalid: expired or never defined</error> 입니다.
둘 다 원래 요청 (GET /api/Contacts.json?access_token=7c6f5) 및 하위 요청 위치 (/threescale_authrep) 및 업스트림 요청 ( upstream: "hits=1&access_token=7c6f5".)을 출력합니다.) 이 마지막 값을 사용하면 3scale IP 중 어떤 것이 해결되었는지와 3scale의 정확한 요청도 확인할 수 있습니다.