From 82f8f22e4c7d6b4b3d29ca0c876167476a4005d5 Mon Sep 17 00:00:00 2001 From: Shreyas Zare Date: Sun, 3 Mar 2019 19:29:21 +0530 Subject: [PATCH] added X-Real-IP support to get client IP from reverse proxy. --- DnsServerCore/DnsWebService.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/DnsServerCore/DnsWebService.cs b/DnsServerCore/DnsWebService.cs index fb310deb..c811ceb0 100644 --- a/DnsServerCore/DnsWebService.cs +++ b/DnsServerCore/DnsWebService.cs @@ -536,8 +536,16 @@ namespace DnsServerCore return; } + string xRealIp = request.Headers["X-Real-IP"]; string xForwardedFor = request.Headers["X-Forwarded-For"]; - if (!string.IsNullOrEmpty(xForwardedFor)) + + if (!string.IsNullOrEmpty(xRealIp)) + { + //get the real IP address of the requesting client from X-Real-IP header set in nginx proxy_pass block + + remoteEP = new IPEndPoint(IPAddress.Parse(xRealIp), 0); + } + else if (!string.IsNullOrEmpty(xForwardedFor)) { //get the real IP address of the requesting client from X-Forwarded-For header set in nginx proxy_pass block string[] xForwardedForParts = xForwardedFor.Split(new char[] { ',' }, StringSplitOptions.RemoveEmptyEntries);