How to configure nginx to serve as a load balancer for gRPC?

2,432 views
Skip to first unread message

alexm...@gmail.com

unread,
Aug 29, 2017, 1:54:08 PM8/29/17
to grpc.io

I understand that the question is more appropriate for nginx group, but still... Does anyone have a _working_ nginx.conf file that does the job?
I ended up with 404 from nginx sending gRPC requests (yes, valid requests, verified) with the following nginx.conf:

events {
  worker_connections  4096;  ## Default: 1024
}

http {
  upstream ip-10-100-30-92 {
    server ip-10-100-30-147:50101;
    server ip-10-100-130-12:50101;
  }

  server {
    listen 50101;
    server_name ip-10-100-30-92;
    location / {
      proxy_pass http://ip-10-100-30-92;
    }
  }
}

This file produces 404 response and a line in /var/log/nginx/access.log:

192.168.13.238 - - [29/Aug/2017:16:56:34 +0000] "PRI * HTTP/2.0" 400 173 "-" "-"

Actually, I try to use SSL, and a _working_ example of nginx.conf would be _really_ appreciated.

Osman Ali

unread,
Aug 31, 2017, 12:06:41 AM8/31/17
to grpc.io, alexm...@gmail.com
Nginx currently doesn't send http2 to your upstream location. You would be sending http 1.1 after nginx terminates. 

You can use other options:


Josh Humphries

unread,
Aug 31, 2017, 11:34:18 AM8/31/17
to Osman Ali, grpc.io, alexm...@gmail.com
You could use nginx as a TCP load balancer (layer 4), instead of HTTP (layer 7). However, the actual load balancing performance will likely be much worse, especially if clients are using long-lived persistent connections without any sort of client-side load balancing logic (like opening multiple connections and using some scheme, like round-robin, to fan out requests to those connections).

I think there may even be a way to combine TCP load balancing with TLS termination, though I think there was an issue relating to ALPN (used to negotiate http/2 protocol during TLS handshake). Here's a related thread: https://groups.google.com/d/topic/grpc-io/mPcCdVEo-fM/discussion


----
Josh Humphries
jh...@bluegosling.com

--
You received this message because you are subscribed to the Google Groups "grpc.io" group.
To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+unsubscribe@googlegroups.com.
To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/bb919b89-1923-45b9-9afc-02eba0ac0399%40googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

alexm...@gmail.com

unread,
Aug 31, 2017, 12:40:37 PM8/31/17
to grpc.io, osman...@gmail.com, alexm...@gmail.com
Thank you both for your replies. I already tried both nghttp2 and envoy w/o success.
I decided to wait a bit, because https://grpc.io/blog/loadbalancing says "Nginx coming soon".

----
Josh Humphries
jh...@bluegosling.com

To unsubscribe from this group and stop receiving emails from it, send an email to grpc-io+u...@googlegroups.com.

To post to this group, send email to grp...@googlegroups.com.
Visit this group at https://groups.google.com/group/grpc-io.
Reply all
Reply to author
Forward
Message has been deleted
0 new messages