1 year ago
#275220
wind.leon
Connect NGINX proxy to Envoy for gRPC-Web
I am currently developing a webapp with a gRPC backend. For this I am using gRPC-Web and the Envoy proxy between the webapp and the backend service. It is all going fine but now I wanted to deploy it to a digitalocean server and was setting up NGINX as a reverse proxy and to serve my index.html
file. The following is basically my architecture with the ports of the individual services. The Envoy proxy and the gRPC backend are running in Docker containers:
My nginx.conf
now looks like this:
server {
listen 80;
listen [::]:80;
root /var/www/;
index index.html index.htm;
server_name myDomain.com
location / {
try_files $uri $uri /index.html?$args;
}
location /api {
proxy_http_version 1.1;
proxy_pass http://localhost:8000;
proxy_set_header Connection "";
}
}
Now I am getting the error
grpc-message: "unknown service api/proto.Service"
grpc-status: "12"
even if the method is implemented and it is running great locally. Any help is highly appreciated :)
EDIT:
After some debugging, I am thinking that returning the answer from the service through Envoy and Nginx is the issue.
For example, when I send the request while the Envoy proxy is running BUT the backend service is not running, I am getting the correct error 503 (Service Unavailable)
.
As soon as the backend gRPC service is running again, I am reciving the unkown service api/proto.Service
error.
As requested, my docker-compose.yaml
file:
version: "3.9"
services:
postgres:
container_name: postgres
hostname: postgres
volumes:
- ./management/postgres/postgres_data:/var/lib/postgresql/data
build: ./management/postgres/
ports:
- "5432:5432"
environment:
- POSTGRES_USER=$DB_USER
- POSTGRES_PASSWORD=$DB_PWD
- POSTGRES_DB=$DB_NAME
backend:
container_name: backend
ports:
- "50051:50051"
depends_on:
- postgres
build: ./service
environment:
- POSTGRES_PASSWORD=$DB_PWD
envoy:
build: ./management/proxies
ports:
- "8000:8000"
My envoy.yaml
proxy:
admin:
access_log_path: /tmp/admin_access.log
address:
socket_address: { address: 0.0.0.0, port_value: 9901 }
static_resources:
listeners:
- name: listener_0
address:
socket_address: { address: 0.0.0.0, port_value: 8000 }
filter_chains:
- filters:
- name: envoy.filters.network.http_connection_manager
typed_config:
"@type": type.googleapis.com/envoy.extensions.filters.network.http_connection_manager.v3.HttpConnectionManager
codec_type: auto
stat_prefix: ingress_http
route_config:
name: local_route
virtual_hosts:
- name: local_service
domains: ["*"]
routes:
- match: { prefix: "/" }
route:
cluster: grpc_server
timeout: 0s
max_stream_duration:
grpc_timeout_header_max: 0s
cors:
allow_origin_string_match:
- prefix: "*"
allow_methods: GET, PUT, DELETE, POST, OPTIONS
allow_headers: keep-alive,user-agent,cache-control,content-type,content-transfer-encoding,custom-header-1,x-accept-content-transfer-encoding,x-accept-response-streaming,x-user-agent,x-grpc-web,grpc-timeout
max_age: "1728000"
expose_headers: custom-header-1,grpc-status,grpc-message
http_filters:
- name: envoy.filters.http.grpc_web
- name: envoy.filters.http.cors
- name: envoy.filters.http.router
clusters:
- name: grpc_server
connect_timeout: 0.25s
type: logical_dns
http2_protocol_options: {}
lb_policy: round_robin
load_assignment:
cluster_name: cluster_0
endpoints:
- lb_endpoints:
- endpoint:
address:
socket_address:
address: backend
port_value: 50051
nginx
grpc
reverse-proxy
envoyproxy
grpc-web
0 Answers
Your Answer