Skip to content

Conversation

ArtARTs36
Copy link
Contributor

@ArtARTs36 ArtARTs36 commented Aug 1, 2025

Hi. This pull request adds the ability to forward the client's real IP address to the gRPC backend.

gRPC backend can get the real IP address of the client using a similar snippet:

func UserIP(ctx context.Context) string {
	md, ok := metadata.FromIncomingContext(ctx)
	if ok {
		if xRealIP := md.Get("x-real-ip"); len(xRealIP) > 0 {
			return strings.Split(xRealIP[0], ",")[0]
		}
	}
	p, ok := peer.FromContext(ctx)
	if ok {
		return p.Addr.String()
	}
	return ""
}

@buchdag buchdag added the type/feat PR for a new feature label Aug 3, 2025
@buchdag buchdag changed the title Pass X-Real-IP to gRPC Backend feat: pass X-Real-IP to gRPC Backend Aug 3, 2025
@buchdag buchdag changed the title feat: pass X-Real-IP to gRPC Backend feat: pass X-Real-IP header to gRPC Backend Aug 3, 2025
@buchdag
Copy link
Member

buchdag commented Aug 3, 2025

Thanks @ArtARTs36

@buchdag buchdag merged commit a2bdbcd into nginx-proxy:main Aug 3, 2025
6 of 10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/feat PR for a new feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants