grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.56k stars 762 forks source link

Use Nginx in front of Envoy #1213

Open leonwind opened 2 years ago

leonwind commented 2 years ago

Hey, I am currently setting up a new webapp I have been building using gRPC as a backend and I want to now send my client gRPC requests to Nginx on my domain domain/api which then should forward it to the Envoy proxy running on port :8000. The architecture looks roughly like this:

image

Now in my webapp I want to create a new client to send the data to my service like this:

this.service = new Client("/api", null, null);

This doesn't work and I am getting the error:

grpc-message: "unknown service api/proto.Service"
grpc-status: "12"

If I expose the Envoy port and send the requests there directly with

this.service = new Client("http://domain.com:8000", null, null);

it works perfectly but I would rather send the request to Nginx first and let it distribute to Envoy.

My nginx.conf looks like the following:

server {
        listen 80;
        root /var/www/domain.com/html;
        index index.html index.htm index.nginx-debian.html;

        server_name domain.com www.domain.com;

        location /api {
                proxy_http_version 1.1;
                proxy_pass http://localhost:8000;
                proxy_set_header Connection "";
        }

        location / {
                try_files $uri $uri/ /index.html$is_args$args;
        }
}

My question is now how do I fix it and get Nginx to forward the requests correctly while sending the requests to domain.com/api.

Thanks a lot for any help :) Best, Leon

wsdl-king commented 1 year ago

for example my backend protoServer is ip:10000/notice.NoticeService then i will config my nginx conf

upstream grpc { server ip:10000; }

location /notice.NoticeService/ {

proxy_http_version 1.1;

      # proxy_pass http://grpc;
      grpc_pass grpc://grpc;
    }

Release the first two lines of comments for the above configuration and comment on the last line of configuration. The effect is equivalent So after my nginx configuration, I can directly use http://ip/notice.NoticeService/xx To access my grpc service