英文:
Nginx configuration in OS X
问题
以下是翻译好的内容:
我想为 gRPC 客户端和服务器实现服务器端负载平衡,并尝试创建适用于 OS X 的简单 Nginx 配置。我有两个运行在端口 50051 和 50052 上的服务器,以下是我启动服务器的代码:
Server server = ServerBuilder.forPort(50051)
.addService(new ImageStreamingServerImpl())
.addService(ProtoReflectionService.newInstance())
// .useTransportSecurity(
// new File("ssl/server.crt"),
// new File("ssl/server.pem")
// )
.build();
server.start();
这是我的 Nginx 配置:
worker_processes 1;
error_log /usr/local/var/log/nginx/error.log;
events {
worker_connections 10;
}
http {
access_log /usr/local/var/log/nginx/access.log;
upstream backend {
server 0.0.0.0:50051;
server 0.0.0.0:50052;
}
server {
listen 8080;
location / {
grpc_pass grpc://backend;
}
}
}
所以我的想法是客户端可以通过 Nginx 上的端口 8080 进行监听,并执行与之前相同的代码。客户端的创建如下:
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080)
.usePlaintext()
.build();
// ManagedChannel channel = NettyChannelBuilder.forAddress("localhost", 8080)
// .sslContext(GrpcSslContexts.forClient().trustManager(new File("ssl/ca.crt")).build())
// .build();
FileServiceGrpc.FileServiceStub imageStreamingClient = FileServiceGrpc.newStub(channel);
以前,客户端和服务器可以在同一个端口上(例如,50051 或 50052)良好运行,而不需要 Nginx。为什么现在不起作用呢?
以下是提供的 proto 文件内容:
syntax = "proto3";
option java_multiple_files = true;
package com.grpc.protobuf;
message DownloadFileRequest {
string url = 1;
}
message DataChunk {
bytes data = 1;
int32 size = 2;
}
service FileService {
rpc downloadFile (DownloadFileRequest) returns (stream DataChunk);
}
我为了简化目的省略了 TLS 加密部分。
英文:
I want to server-side load balance for gRPC client and server and trying to come up with simple Nginx config for the OS X. I have 2 servers running on the port 50051 and 50052 and this is I start the server:
Server server = ServerBuilder.forPort(50051)
.addService(new ImageStreamingServerImpl())
.addService(ProtoReflectionService.newInstance())
// .useTransportSecurity(
// new File("ssl/server.crt"),
// new File("ssl/server.pem")
// )
.build();
server.start();
This is my Nginx config:
worker_processes 1;
error_log /usr/local/var/log/nginx/error.log;
events {
worker_connections 10;
}
http {
access_log /usr/local/var/log/nginx/access.log;
upstream backend {
server 0.0.0.0:50051;
server 0.0.0.0:50052;
}
server {
listen 8080;
location / {
grpc_pass grpc://backend;
}
}
}
So my idea is the client can listen to the port of 8080 over the Nginx and perform the code as before. Client creation is below:
ManagedChannel channel = ManagedChannelBuilder.forAddress("localhost", 8080)
.usePlaintext()
.build();
// ManagedChannel channel = NettyChannelBuilder.forAddress("localhost", 8080)
// .sslContext(GrpcSslContexts.forClient().trustManager(new File("ssl/ca.crt")).build())
// .build();
FileServiceGrpc.FileServiceStub imageStreamingClient = FileServiceGrpc.newStub(channel);
Previously, the client and server can run decently in the same port (say, 50051 or 50052) without Nginx. Why does this not working now?
The proto file is provided below:
syntax = "proto3";
option java_multiple_files = true;
package com.grpc.protobuf;
message DownloadFileRequest {
string url = 1;
}
message DataChunk {
bytes data = 1;
int32 size = 2;
}
service FileService {
rpc downloadFile (DownloadFileRequest) returns (stream DataChunk);
}
I omit the TLS encryption for the simplification purpose.
答案1
得分: 4
这似乎你还没有配置Nginx来启用HTTP2,而这是gRPC使用的协议。
尝试使用:
server {
listen 8080 http2;
....
}
英文:
It doesn't look like you have configured Nginx to enabled HTTP2, which is the protocol used by gRPC.
Try with:
server {
listen 8080 http2;
....
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论