nginx + grpc-web
donald.williams.0018
nginx-forum at forum.nginx.org
Thu Jun 28 15:19:38 UTC 2018
I try to use nginx + grpc + grpc-web client JS library
(https://github.com/grpc/grpc-web).
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
/github/grpc-web/third_party/grpc'
--with-ld-opt='-L/github/grpc-web/third_party/grpc/third_party/protobuf/src/.libs
-L/github/grpc-web/third_party/grpc/libs/opt -lgrpc++ -lgrpc -lprotobuf
-lpthread -ldl -lrt -lstdc++ -lm'
--with-openssl=/github/grpc-web/third_party/openssl
--add-module=/github/grpc-web/net/grpc/gateway/nginx
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;
pid nginx.pid;
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'
'DNT,X-CustomHeader,Keep-Alive,User-Agent,X-Requested-With,If-Modified-Since,Cache-Control,Content-Type,Content-Transfer-Encoding,Custom-Header-1,X-Accept-Content-Transfer-Encoding,X-Accept-Response-Streaming,X-User-Agent';
add_header 'Access-Control-Expose-Headers'
'Content-Transfer-Encoding';
}
}
}
}
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: 192.168.50.101, server:
localhost, request: "POST /helloworld.Greeter/SayHello HTTP/1.1", upstream:
"grpc://127.0.0.1:50051", host: "localhost:8080", referrer:
"http://localhost:8080/hello.html"
>From the chrome console, I received the following error
POST http://localhost:8080/helloworld.Greeter/SayHello 502 (Bad
Gateway)
goog.net.XhrIo.send @ compiled.js:395
module$contents$grpc$web$GrpcWebClientBase_GrpcWebClientBase.rpcCall @
compiled.js:438
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 Object.goog.crypt.base64.decodeStringInternal_ (compiled.js:429)
at Object.goog.crypt.base64.decodeStringToUint8Array
(compiled.js:428)
at goog.net.XhrIo.<anonymous> (compiled.js:432)
at goog.net.XhrIo.goog.events.EventTarget.fireListeners
(compiled.js:279)
at Function.goog.events.EventTarget.dispatchEventInternal_
(compiled.js:281)
at goog.net.XhrIo.goog.events.EventTarget.dispatchEvent
(compiled.js:276)
at goog.net.XhrIo.onReadyStateChangeHelper_ (compiled.js:401)
at goog.net.XhrIo.onReadyStateChangeEntryPoint_ (compiled.js:400)
at goog.net.XhrIo.onReadyStateChange_ (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
issue?
Thanks a lot!
Don
Posted at Nginx Forum: https://forum.nginx.org/read.php?2,280325,280325#msg-280325
More information about the nginx
mailing list