I am using an Azure WebApp (docker-compose) which has Nginx as reverse proxy and .net core app. Last year our number of clients increased a lot and we started using Azure Front Door as CDN for caching static content. Problem is now we no longer are able to get client IP address for our logging SQL table.
This is the code that works without the AFD:
Nginx default.conf:
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header X-Forwarded-Proto $scheme;
Dotnet Startup.cs:
app.UseForwardedHeaders(new ForwardedHeadersOptions
{
ForwardedHeaders = ForwardedHeaders.XForwardedFor | ForwardedHeaders.XForwardedProto
});
But adding the AFD it always gets the IP address of the CDN.
I know AFD passes X-Azure-ClientIP
header, but I was not able to get it in Nginx or dotnet.
Do you know how can I get real client IP address using Azure Front Door, Nginx and dotnet core?
Thanks in advance.
2
Answers
It worked this way:
dotnet:
Azure Front Door saves the client IP information in its own logs. In the Azure Portal you can access these logs by going to the "Logs" blade:
You can query the information using Kusto, for example, this query will retrieve the timestamp, request URI, and client IP for all requests in the previous 15 minutes:
If you wanted to pull this information into your own SQL logs you can programmatically retrieve it using an Azure Logic App, Azure Runbook with a Powershell query, or several other solutions.