I have deployed a sample grpc service on my ubuntu server with .net core 3.1. I am able to connect using a plain HTTP URL but when trying to access it via reverse proxy I am getting a Bad grpc response error
my ngnix setting is like
server {
listen 80;
server_name abc.def.net;
location / {
proxy_pass http://10.10.10.10:8086/;
proxy_next_upstream error http_502;
proxy_redirect off;
server_tokens off;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
client_max_body_size 25m;
client_body_buffer_size 256k;
proxy_connect_timeout 180;
proxy_send_timeout 180;
proxy_read_timeout 180;
proxy_buffer_size 8k;
proxy_buffers 8 32k;
proxy_busy_buffers_size 64k;
proxy_temp_file_write_size 64k;
proxy_buffering on;
access_log /var/log/nginx/abc.def.net_access_log ;
error_log /var/log/nginx/abc.def.net_error_log notice;
}
}
My code for accessing the grpc service is like
var serverAddress = "https://abc.def.net/";
// var serverAddress = "http://10.10.10.10:8086/";
//AppContext.SetSwitch("System.Net.Http.SocketsHttpHandler.Http2UnencryptedSupport", true);
var channel = GrpcChannel.ForAddress(serverAddress);
var client = new CreditRatingCheck.CreditRatingCheckClient(channel);
var creditRequest = new CreditRequest { CustomerId = "id0201", Credit = 7000 };
var reply = client.CheckCreditRequest(creditRequest);
Console.WriteLine($"Credit for customer {creditRequest.CustomerId} {(reply.IsAccepted ? "approved" : "rejected")}!");
Console.WriteLine("Press any key to exit...");
Console.ReadKey();
2
Answers
Problem was in nginx file. we have to use grpc_pass instead of proxy_pass
Only adding a config example how we used it (per the request of one of the above commenter)
In this,
[serviceName]
with the sub path if needed, or remove if not used.