可以在Program中进行配置
var host = Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
webBuilder.ConfigureKestrel(options =>
{
var httpPort = Environment.GetEnvironmentVariable("HTTP_PORT") ?? "80";
var gRpcPort = Environment.GetEnvironmentVariable("GRPC_PORT") ?? "8000";
int.TryParse(gRpcPort, out var intRpcPort);
int.TryParse(httpPort, out var intHttpPort);
//设置监听端口信息
options.ListenAnyIP(intHttpPort, listenOption =>
{
//设置Api接口
listenOption.Protocols = HttpProtocols.Http1AndHttp2;
});
options.ListenAnyIP(intRpcPort, listenOption =>
{
//设置grpc接口
listenOption.Protocols = HttpProtocols.Http2;
});
}).UseStartup<Startup>();
})