netty支持https

在 集成  ChannelInitializer<SocketChannel> 实现

File certificate = new File("/Users/wucao/Desktop/https/1_gw2.vsgames.cn_bundle.crt"); // 证书
File privateKey = new File("/Users/wucao/Desktop/https/private.pem"); // 私钥
final SslContext sslContext = SslContextBuilder.forServer(certificate, privateKey).build();

protected void initChannel(SocketChannel ch) throws Exception {
ChannelPipeline pipeline = ch.pipeline();


// 加入SslHandler实现HTTPS
SslHandler sslHandler = sslContext.newHandler(ch.alloc());
pipeline.addLast(sslHandler);

pipeline.addLast("decoder", new HttpRequestDecoder());
pipeline.addLast("encoder", new HttpResponseEncoder());
pipeline.addLast("deflater", new HttpContentCompressor());
pipeline.addLast("handler", new HttpServerHandler());
}

即可

原文地址:https://www.cnblogs.com/hui413027075/p/8391281.html