grpc.github.io icon indicating copy to clipboard operation
grpc.github.io copied to clipboard

Write a doc and sample on how to use gRPC with nginx

Open zinuga opened this issue 9 years ago • 29 comments

zinuga avatar Jul 07 '16 22:07 zinuga

@fengli-google would you be able to help out with this?

hsaliak avatar Jul 08 '16 16:07 hsaliak

@fengli-google have you had a chance to look into this? @zinuga is P2 the right priority for this content?

hsaliak avatar Aug 09 '16 20:08 hsaliak

yes, we can drop this from GA milestone.

zinuga avatar Aug 09 '16 20:08 zinuga

Please! I could use this documentation right away. Bummer that gRPC isn't further along - esp. with respect to NGINX

shulegaa avatar Sep 02 '16 21:09 shulegaa

This may be relevant https://trac.nginx.org/nginx/ticket/923

clehene avatar Sep 02 '16 21:09 clehene

@shulegaa we are in the process of submitting a 3rd party module in nginx for grpc support. we cant control the nginx core code or timeline for http/2 support. for now, if its critical for your needs, we can point you to a custom nginx binary where we have built support for grpc.(usable for testing/prototyping).

zinuga avatar Sep 02 '16 23:09 zinuga

Do tell! Please. I'd be very interested in seeing what you've done. Depending on timing, we may go down a similar path. Long story.

shulegaa avatar Sep 08 '16 01:09 shulegaa

I use nginx1.10 which support http2 as grpc server proxy, then go grpc client send a request to server, from nginx debug log, I find such message:

2016/09/12 14:48:57 [debug] 14677#14677: *1 SSL certificate status callback
2016/09/12 14:48:57 [debug] 14677#14677: *1 SSL NPN advertised

2016/09/12 14:48:57 [debug] 14677#14677: *1 http2 preface verified
2016/09/12 14:48:57 [debug] 14677#14677: *1 process http2 frame type:4 f:0 l:0 sid:0
2016/09/12 14:48:57 [debug] 14677#14677: *1 http2 send SETTINGS frame ack:1
2016/09/12 14:48:57 [debug] 14677#14677: *1 http2 frame complete pos:00007F5DA7C0A5F1 end:00007F5DA7C0A5FE

2016/09/12 14:48:57 [info] 14677#14677: *1 client sent stream with data before settings were acknowledged while processing HTTP/2 connection, client: 127.0.0.1, server: 0.0.0.0:443

nginx can receive the connection preface starts with the string PRI * HTTP/2.0\r\n\r\nSM\r\n\r\n), but it send a RST_STREAM frame, and refuse to accpet any request.

Nginx http2 supports required a ack before client send data frame, I know that.

When I use go http2 to send a http request, the nginx can response succeed. So what's difference and reason for that?

Anyone helps

@fengli79 @zinuga @hsaliak @shulegaa @clehene @fengli-google

wangming1993 avatar Sep 12 '16 07:09 wangming1993

@zinuga could you please also point me to your 3rd party nginx module for grpc support? thanks

danaschwanden avatar Sep 15 '16 04:09 danaschwanden

Nginx today doesn't support HTTP2 as upstream, so you cannot use it as a L7 proxy for GRPC. Instead you can use it as a L4 proxy.

For the RST_STREAM issue, it's a known regression in nginx. https://trac.nginx.org/nginx/ticket/959

fengli79 avatar Sep 15 '16 18:09 fengli79

@zinuga Hi, I'm also considering grpc and nginx for my next project. Can you please kindly share the source code of that nginx module? I'm not interested in binary blobs :-) Thanks!

@fengli79 BTW that NGINX RST_STREAM regression seems to be fixed.

ynezz avatar Oct 30 '16 08:10 ynezz

@zinuga could you please also point me to your 3rd party nginx module for grpc support? thanks

hoswey avatar Jan 25 '17 06:01 hoswey

Much needed feature indeed, I saw some posts on the internet talking about ngx_stream_core_module

amitripshtos avatar Feb 07 '17 14:02 amitripshtos

@zinuga same here

xiaoyunwu avatar Mar 14 '17 14:03 xiaoyunwu

I went a bit of exploring and understood it better, and created a load balancer that balance automatic using docker + consul: https://github.com/amitripshtos/grpc-docker-lb

i'm using nghttp2 for this one, by the way

amitripshtos avatar Mar 14 '17 20:03 amitripshtos

@zinuga same here, it seems nginx supports HTTP/2 but not full. Any updates now?

ggaaooppeenngg avatar Apr 13 '17 13:04 ggaaooppeenngg

@zinuga same here, thanks.:)

idevz avatar Jun 02 '17 03:06 idevz

@zinuga same here (https://github.com/grpc/grpc/issues/11427)

thanks!

siacomuzzi avatar Jun 07 '17 18:06 siacomuzzi

based on this https://github.com/grpc/grpc/issues/11427, it is matter of a few weeks now before its upstreamed. credit @PiotrSikora. once done, @LisaFC can help with doc on how to use.

zinuga avatar Jun 08 '17 01:06 zinuga

There are some fixes provided by @PiotrSikora in the latest versions of nginx (http://nginx.org/en/CHANGES):

Changes with nginx 1.13.2                                        27 Jun 2017

    *) Feature: the "add_trailer" directive.
       Thanks to Piotr Sikora.

    *) Bugfix: in the ngx_http_v2_module.
       Thanks to Piotr Sikora.

Do you know if we can use gRPC with nginx now? Thanks!

siacomuzzi avatar Jul 21 '17 16:07 siacomuzzi

@siacomuzzi unfortunately, those are only prerequisites and bugfixes for existing HTTP/2 server-side code. HTTP/2 to backends is still pending review / merge.

PiotrSikora avatar Jul 21 '17 23:07 PiotrSikora

Hello wangming1993, PiotrSikora

Could you please share the working nginx.conf. We are seeing that our nginx h2 proxy(taken from PiotrSikora github) is not forwarding to gRPCServer. our conf file part looks below: server { listen 8443 ssl http2; listen [::]:8443 ssl http2; ssl_certificate /f0/base/nginx/ssl/certs/server.crt; ssl_certificate_key /f0/base/nginx/ssl/private/server.key; # ...

location / {
    proxy_pass http://10.220.73.160:50051;
    proxy_set_header X-Real-IP $remote_addr;
    allow all;
}

10.220.73.160 is the Network element, that has gRPCServer running.

nginx -v

nginx version: nginx/1.13.2

Thanks for help.

Best Regards, Div

dyadaval avatar Sep 12 '17 11:09 dyadaval

what is the update on using nginx with grpc?

asinha08 avatar Oct 14 '17 21:10 asinha08

No, was not lucky with the patch to get it working. You can use haproxy with grpc.

On Sun, Oct 15, 2017 at 2:51 AM, Ashish Sinha [email protected] wrote:

what is the update on using nginx with grpc?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/grpc/grpc.github.io/issues/230#issuecomment-336668326, or mute the thread https://github.com/notifications/unsubscribe-auth/AS4RIa7n059Ft806GmCaO4qJIz0RaX9dks5ssSXmgaJpZM4JHi3Q .

dyadaval avatar Oct 15 '17 00:10 dyadaval

So for anyone else here that want's to know the config to make it work I managed to get it going using @PiotrSikora patch. You need to disable buffering in order to make grpc streams work. @PiotrSikora, any idea if they plan to pull this? Pretty happy it works and it would help me out a lot.

location /grpcpackagename.grpcservicename {
        proxy_pass https://127.0.0.1:1234;
        proxy_http_version 2.0;
        proxy_pass_trailers on;
        proxy_request_buffering off;
        proxy_buffering off;
}

snowzach avatar Dec 15 '17 04:12 snowzach

waiting for good news

pathbox avatar Jan 06 '18 09:01 pathbox

@snowzach I am trying GRPC with nginx, can you please let me know detail of config "location /grpcpackagename.grpcservicename"

mishika186 avatar Jan 07 '18 10:01 mishika186

@mritunjayblr it's basically just that.. GRPC is listening at a url of whatever the GRP package name is followed by the service name...

So if in your proto definition you have

package bob

service barker { rpc blahblahbl;ah }

your GRPC is technically listening at /bob.barker on your HTTP2 server.

snowzach avatar Jan 16 '18 17:01 snowzach

If folks want to, happy to contribute the example based on what I did in https://github.com/mhausenblas/kruiser/blob/master/how-does-it-work.md … however, I'm still struggling with serving from non-root URL. So works fine with location / but not /yages.Echo.

mhausenblas avatar Mar 30 '18 12:03 mhausenblas

Good news finally comes! https://www.nginx.com/blog/nginx-1-13-10-grpc/

mdkma avatar Apr 03 '18 07:04 mdkma