赞
踩
打开阿里云控制台,进入SSL证书管理,选择Tomcat证书下载
将下载的证书(pfx证书和txt秘钥)复制到项目中
# 端口:9443或443
server.port=9443
# 开启http2协议
server.http2.enabled=true
# 进行SSL加密协议
server.ssl.enabled=true
# 证书路径
server.ssl.key-store=classpath:9260452_www.yunkeyo.com.pfx
# 秘钥
server.ssl.key-store-password=hxxhtf0a
# 秘钥方式:PKCS12默认
server.ssl.key-store-type=PKCS12
@Bean public FilterRegistrationBean<OncePerRequestFilter> httpsRedirectFilter() { FilterRegistrationBean<OncePerRequestFilter> filterRegistrationBean = new FilterRegistrationBean<>(); filterRegistrationBean.setFilter(new OncePerRequestFilter() { @Override protected void doFilterInternal(HttpServletRequest request, HttpServletResponse response, FilterChain filterChain) throws ServletException, IOException { if (!request.isSecure()) { String url = "https://" + request.getServerName() + request.getRequestURI(); response.sendRedirect(url); return; } filterChain.doFilter(request, response); } }); filterRegistrationBean.setOrder(Ordered.HIGHEST_PRECEDENCE); return filterRegistrationBean; }
注意:此处必须为https,因为http协议已经被关闭了,如果需要http协议同样生效,请自行删除上述代码
发送http2协议请求 成功!
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。