How to configure x-forwarded-for in ASP for nginx access logs to show real ip?

Atul Ajmani 1 Reputation point
2021-11-19T10:53:09.767+00:00

We have a website with Nginx on Azure App Service Plan (ASP). We are analysing the access logs to find the geo locations of our visitors through IP addresses. ASP has a virtual IP and access logs do not show the actual IP of the visitors. There seems to be a way to configure Access Restrictions to populate x-forwarded-for field which we have setup in the Nginx configuration. I have used the inbound IP of our App Service Plan, the configuration is not working and the Azure documentation is not helpful. Nginx.conf file is:

user nginx;
worker_processes auto;

error_log /var/log/nginx/error.log error;
pid /var/run/nginx.pid;

events {
worker_connections 2048;
}

http {
include /etc/nginx/mime.types;
default_type application/octet-stream;

log_format  main  '$http_x_forwarded_for - $remote_user [$time_local] "$request" '
                  '$status $body_bytes_sent "$http_referer" '
                  '"$http_user_agent" ';

access_log /var/log/nginx/access.log;


sendfile        on;

include /etc/nginx/conf.d/*.conf;
include /etc/nginx/modules-enabled/*.conf;
Azure Monitor
Azure Monitor
An Azure service that is used to collect, analyze, and act on telemetry data from Azure and on-premises environments.
2,665 questions
0 comments No comments
{count} votes