Please see the FAQ in our main README.md before submitting your issue.
google.golang.org/grpc v1.22.1
go version)?go version go1.12.5 linux/amd64
Linux version 4.15.0-66-generic (buildd@lgw01-amd64-044) (gcc version 7.4.0 (Ubuntu 7.4.0-1ubuntu1~18.04.1)) #75-Ubuntu SMP Tue Oct 1 05:24:09 UTC 2019
nginx and gRPC server in one host whose IP(LAN) is 192.168.90.20
gRPC client in another host whose IP(LAN) is 192.168.90.24
(1). use nginx for gRPC server, config file(path: /etc/nginx/conf.d/gRPC.conf) nginx.conf is default, gRPC.conf content as follow:
upstream backend {
server 127.0.0.1:9090;
server 127.0.0.1:9091;
server 127.0.0.1:9092;
}
server {
listen 9099 http2;
access_log /var/log/nginx/access-grpc.log;
location / {
grpc_pass grpc://127.0.0.1:9091;
#grpc_pass grpc://backend;
}
}
(2). I will get client real ip in server side by code as follow:
// peer is from package "google.golang.org/grpc/peer"
if grpcPeer, ok := peer.FromContext(ctx); ok {
if tcpAddr, ok := grpcPeer.Addr.(*net.TCPAddr); ok {
externalIP := tcpAddr.IP
grpclog.Warningf("get the external-ip=%s", externalIP)
return externalIP
}
}
// log in server side:
... get the external-ip=192.168.90.24
// log in nginx:
192.168.90.24 - - [07/Nov/2019:11:31:38 +0800] "POST /pb.Tracker/FindResource HTTP/2.0" 200 36 "-" "grpc-go/1.22.0"
// log in server side:
WARNING: 2019/11/07 11:36:08 get the external-ip=127.0.0.1
Could you please describe in more detail what you did, what you expected, and what you found instead.
This issue is labeled as requiring an update from the reporter, and no update has been received after 7 days. If no update is provided in the next 7 days, this issue will be automatically closed.
@easwars
I solved my problem as follow:
server {
listen 9099 http2;
access_log /var/log/nginx/access-grpc.log;
location / {
grpc_pass grpc://127.0.0.1:9091;
grpc_set_header X-Real-IP $remote_addr;
}
}
md, ok := metadata.FromIncomingContext(ctx)
...
md.Get("x-real-ip")
...
Most helpful comment
I solved my problem as follow:
nginx for gPRC
my code: