.Net单个项目同时包含ResufulAPI和Grpc的配置

发布时间 2023-04-27 17:25:59作者: LazYu

错误 ingress-nginx 502upstream sent too large http2 frame: 4740180 while reading response header from upstream

		// .Net6 Program.cs
		builder.WebHost.ConfigureKestrel(options =>
                {
                    // Set up endpoint for HTTP/1
                    options.Listen(IPAddress.Any, 80, listenOptions =>
                    {
                        listenOptions.Protocols = HttpProtocols.Http1;
                    });

                    // Set up endpoint for HTTP/2 (for gRPC)
                    options.Listen(IPAddress.Any, 8080, listenOptions =>
                    {
                        listenOptions.Protocols = HttpProtocols.Http2;
                    });
                });
				
		// .net5 Program.cs
		public static IHostBuilder CreateHostBuilder(string[] args) =>
            		Host.CreateDefaultBuilder(args).ConfigureWebHostDefaults(webBuilder =>
            	{
                	webBuilder.ConfigureKestrel((context, options) =>
                	{
                    		if (context.HostingEnvironment.IsProduction())
                    		{
                        		// Set up endpoint for HTTP/1
                        		options.Listen(IPAddress.Any, 80, listenOptions =>
                        		{
                            		listenOptions.Protocols = HttpProtocols.Http1;
                        		});

                        		// Set up endpoint for HTTP/2 (for gRPC)
                        		options.Listen(IPAddress.Any, 8080, listenOptions =>
                        		{
                            		listenOptions.Protocols = HttpProtocols.Http2;
                        		});
                    		}
                	});
                	webBuilder.UseStartup<Startup>();
            });

需要分开端口处理http/1和http/2。