nginx + grpc-web

donald.williams.0018 nginx-forum at
Thu Jun 28 15:19:38 UTC 2018

I try to use  nginx + grpc + grpc-web client JS library

Nginx-1 is compiled using the following setup:
    nginx version: nginx/1.15.0
    built by gcc 7.2.0 (Ubuntu 7.2.0-8ubuntu3.1~16.04.york0)
    built with OpenSSL 1.0.2g  1 Mar 2016
    TLS SNI support enabled
    configure arguments: --with-threads --with-file-aio
--with-http_ssl_module --with-http_v2_module

Nginx-2 that comes with the grpc-web javascript library on docker image is
compiled using the following setup:
    nginx version: nginx/1.11.13
    built by gcc 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9) 
    built with OpenSSL 1.0.2h  3 May 2016
    TLS SNI support enabled
    configure arguments: --with-http_ssl_module --with-http_v2_module
--with-cc-opt='-I /usr/local/include -I /github/grpc-web -I
/github/grpc-web/third_party/grpc/third_party/protobuf/include -I
/github/grpc-web/third_party/grpc/third_party/protobuf/src -I
/github/grpc-web/third_party/grpc/include -I
-L/github/grpc-web/third_party/grpc/libs/opt -lgrpc++ -lgrpc -lprotobuf
-lpthread -ldl -lrt -lstdc++ -lm'

The grpc service is running on port 50051. 

I want to use the grpc-web client JS library to call grpc service from
webpage, and I use the same following nginx.conf for Nginx-1 and Nginx-2. 
    master_process off;
    daemon off;
    worker_processes 1;
    error_log stderr debug;

    events {
      worker_connections 1024;

    http {
      access_log off;
      client_max_body_size 0;
      client_body_temp_path client_body_temp;
      proxy_temp_path proxy_temp;
      proxy_request_buffering off;
      server {
        listen 8080;
        server_name localhost;
        location ~ \.(html|js)$ {
          root html;
        location /helloworld.Greeter {
          grpc_pass localhost:50051;
          if ($request_method = 'OPTIONS') {
            add_header 'Access-Control-Allow-Origin' '*';
            add_header 'Access-Control-Allow-Methods' 'GET, POST, OPTIONS';
            add_header 'Access-Control-Allow-Headers'
            add_header 'Access-Control-Expose-Headers'

If I use Nginx-2, the web JS client can connect to the service.

For Nginx-1, the web JS client cannot connect to the service. Nginx returns
the following error:
    [error] 26125#26125: *1 upstream rejected request with error 2 while
reading response header from upstream, client:, server:
localhost, request: "POST /helloworld.Greeter/SayHello HTTP/1.1", upstream:
"grpc://", host: "localhost:8080", referrer:

>From the chrome console, I received the following error
    POST http://localhost:8080/helloworld.Greeter/SayHello 502 (Bad
Gateway) @ compiled.js:395
    module$contents$grpc$web$GrpcWebClientBase_GrpcWebClientBase.rpcCall @
    proto.helloworld.GreeterClient.sayHello @ compiled.js:631
    echo @ hello.html:49
    send @ hello.html:66
    (anonymous) @ hello.html:78
    dispatch @ jquery.min.js:3
    q.handle @ jquery.min.js:3
    Uncaught Error: Unknown base64 encoding at char: <
        at c (compiled.js:429)
        at (compiled.js:429)
        at<anonymous> (compiled.js:432)
        at (compiled.js:401)
        at (compiled.js:400)
        at (compiled.js:400)

It seems that Nginx-1 might have some issue with the encoding or the
translation of http1 to http2. Do you have any suggestion of what is the

Thanks a lot!

Posted at Nginx Forum:,280325,280325#msg-280325

More information about the nginx mailing list