gRPC 响应错误。 HTTP 状态代码:使用 ngnix 的 https 上的 502。在本地 http 上工作正常
Bad gRPC response. HTTP status code: 502 on https with ngnix. working fine on local http
我已经使用 .net core 3.1 在我的 ubuntu 服务器上部署了一个示例 grpc 服务。我可以使用纯 HTTP URL 进行连接,但是当我尝试通过反向代理访问它时,我收到了 Bad grpc response error
我的 ngnix 设置就像
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;
}
}
我访问grpc服务的代码是这样的
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();
问题出在 nginx 文件中。
我们必须使用 grpc_pass 而不是 proxy_pass
我已经使用 .net core 3.1 在我的 ubuntu 服务器上部署了一个示例 grpc 服务。我可以使用纯 HTTP URL 进行连接,但是当我尝试通过反向代理访问它时,我收到了 Bad grpc response error
我的 ngnix 设置就像
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;
}
}
我访问grpc服务的代码是这样的
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();
问题出在 nginx 文件中。 我们必须使用 grpc_pass 而不是 proxy_pass