Skip to content

feat: pass X-Real-IP header to gRPC Backend #2641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 3, 2025

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