Tomcat10 简单地enable Https

通常来讲, 建站后要启用https 有下面3个步骤

1.购买域名

2.绑定域名和 服务器的外部IP地址

3.为这域名购买SSL 证书 (还有其密码)

4.在Tomcat上启用https 和安装这个证书

但是其实没有域名也可以在tomcat 中enable https的, 至于为什么, 当然是为了实现传输中的数据被加密了。

步骤:

首先是自己生成1个ssl证书, 当然这个证书是不被浏览器信任的, 但是这个是实现https的前提条件

bash 复制代码
keytool -genkey -alias tomcat -keyalg RSA -keystore keystore.jks -validity 36

这个命令会让你输入你想要的密码

还会问你若干关于证书的问题, 随便填就是

然后打开tomcat的server.xml

找到下面的注释, 并反注释它, 填入生成key的路径和密码

bash 复制代码
   <!-- Define an SSL/TLS HTTP/1.1 Connector on port 8443 with HTTP/2
         This connector uses the NIO implementation. The default
         SSLImplementation will depend on the presence of the APR/native
         library and the useOpenSSL attribute of the AprLifecycleListener.
         Either JSSE or OpenSSL style configuration may be used regardless of
         the SSLImplementation selected. JSSE style configuration is used below.
    -->
    <Connector port="8443" protocol="org.apache.coyote.http11.Http11NioProtocol"
               maxThreads="150" SSLEnabled="true"
               maxParameterCount="1000"
               >
        <UpgradeProtocol className="org.apache.coyote.http2.Http2Protocol" />
        <SSLHostConfig>
            <Certificate certificateKeystoreFile="/home/gateman/keys/ssl/keystore.jks"
                         certificateKeystorePassword="xxxxxx"
                         type="RSA" />
        </SSLHostConfig>
    </Connector>

重启tomcat服务器

就是用8443 访问tomcat了

相关推荐
小时前端20 小时前
HTTPS 页面加载 HTTP 脚本被拦?同源代理来救场
前端·https
YuMiao21 小时前
gstatic连接问题导致Google Gemini / Studio页面乱码或图标缺失问题
服务器·网络协议
不可能的是2 天前
前端 SSE 流式请求三种实现方案全解析
前端·http
Jony_4 天前
高可用移动网络连接
网络协议
chilix4 天前
Linux 跨网段路由转发配置
网络协议
gihigo19986 天前
基于TCP协议实现视频采集与通信
网络协议·tcp/ip·音视频
古译汉书6 天前
【IoT死磕系列】Day 7:只传8字节怎么控机械臂?学习工业控制 CANopen 的“对象字典”(附企业级源码)
数据结构·stm32·物联网·http
白太岁6 天前
通信:(5) 电路交换、报文交换与分组交换
运维·服务器·网络·网络协议
EasyGBS6 天前
国标安全升级:GB28181平台EasyGBS支持GB35114协议的应用场景与核心优势
网络协议·安全·gb28181·gb35114
凯酱6 天前
Windows防火墙入站规则IP白名单
windows·网络协议·tcp/ip