I have a configuration to redirect all my local API calls (from a client, with a apikey header) at example.com
to a remote API server distant-api-server.com:8000
).
upstream api-server {
server distant-api-server.com:8000;
}
server {
listen 80;
index index.html;
server_name example.com;
location ~ /api/(?<path>.*) {
if ($request_method = OPTIONS ) {
add_header 'Access-Control-Allow-Origin' "$http_origin";
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
add_header 'Access-Control-Allow-Headers' 'apikey';
return 200;
}
if ($api_route = "error"){return 501;}
error_page 501 /501_apikey.html;
add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS, PUT';
add_header 'Access-Control-Allow-Headers' 'apikey';
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_ssl_session_reuse off;
proxy_set_header Host $http_host;
proxy_redirect off;
}
}
I'd like to log:
- Request send from local server to /api
- Request as sent then by Nginx to http://$api_route/$path$is_args$args
- Response received from distant API and transmitted by Nginx to my client page
For the moment when I make calls to /api, an error on the distant API and then my request time out. By knowing what is sent/received by Nginx would help me debug.
How can I achieve that kind of logging?