tomcat搭建https服务(非自签发)
平时做自己的web demo基本上都是用http协议进行访问。
但是正式情况基本上都是https进行访问,所以掌握https的配置是很关键的。
需要准备的材料:
一台可以可以外网访问的远程服务器
tomcat 8.5
java环境(自行百度安装过程和配置环境变量)
web项目war包(可有可无)
第一步:
在远程服务器上配置好java环境后就是安装tomcat:
详情请见(tomcat安装、配置、使用):https://www.cnblogs.com/longLifeFrog/articles/8612260.html
过程是windows的,但是lunix也大同小异,思路基本一样,可以自行百度搜索相关安装过程
第二步:
由于我这台远程服务器开了2个端口8080和443。
所以这步要完成用tomcat部署2个不同端口的项目。
先将webapps文件夹和conf文件夹下面的Catalina文件夹,copy一份,如下图所示:


接下来是修改conf/server.xml:

代码如下:
<?xml version="1.0" encoding="UTF-8"?> <Server port="8005" shutdown="SHUTDOWN">
<Listener className="org.apache.catalina.startup.VersionLoggerListener" /> <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" />
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" />
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener" /> <GlobalNamingResources> <Resource name="UserDatabase" auth="Container"
type="org.apache.catalina.UserDatabase"
description="User database that can be updated and saved"
factory="org.apache.catalina.users.MemoryUserDatabaseFactory"
pathname="conf/tomcat-users.xml" />
</GlobalNamingResources> <Service name="Catalina">
<!--http配置-->
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" /> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm> <Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" /> </Host>
</Engine>
</Service> <Service name="Catalina2"> <Connector port="443" protocol="HTTP/1.1" connectionTimeout="20000" maxThreads="150"
redirectPort="8443" SSLEnabled="true" scheme="https" secure="true" clientAuth="false" sslProtocol="TLS"
keystoreFile="C:\Program Files\Apache Software Foundation\Tomcat 8.5\www.xxxx.com.jks" keystorePass="xxxxxx"
/> <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> <Engine name="Catalina2" defaultHost="localhost"> <Realm className="org.apache.catalina.realm.LockOutRealm"> <Realm className="org.apache.catalina.realm.UserDatabaseRealm"
resourceName="UserDatabase"/>
</Realm> <Host name="localhost" appBase="webapps2"
unpackWARs="true" autoDeploy="true"> <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
prefix="localhost_access_log" suffix=".txt"
pattern="%h %l %u %t "%r" %s %b" /> </Host>
</Engine>
</Service>
</Server>
上图中8080端口是http形式,如果要将其改成https可以参考443端口的配置。
上图中www.xxxx.com.jks是从权威机构拿到的证书,keystorePass填相应的密码。
第三步:
copy项目到webapps和webapps2,然后运行startup,访问。这样就成功了。

补充:
1、http自动跳转https的安全配置:
到conf目录下的web.xml。在 </welcome-file-list>后面, </web-app>之前,也就是倒数第二段里,加上这样一段:
<login-config>
<!-- Authorization setting for SSL -->
<auth-method>CLIENT-CERT</auth-method>
<realm-name>Client Cert Users-only Area</realm-name>
</login-config>
<security-constraint>
<!-- Authorization setting for SSL -->
<web-resource-collection>
<web-resource-name>SSL</web-resource-name>
<url-pattern>/*</url-pattern>
</web-resource-collection>
<user-data-constraint>
<transport-guarantee>CONFIDENTIAL</transport-guarantee>
</user-data-constraint>
</security-constraint>
结果如下图所示:

这步目的是让非ssl的connector跳转到ssl的connector去。所以还需要前往server.xml进行配置:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />
redirectPort改成ssl的connector的端口443,重启tomcat后便会生效。
以上是权威证书的https配置方法。
最后附上使用jdk的keytool工具生成自签发证书及认证过程(单向和双向认证都能通):https://www.cnblogs.com/longLifeFrog/p/9069715.html
tomcat搭建https服务(非自签发)的更多相关文章
- 用keytool制作证书并在tomcat配置https服务(二 )
用keytool制作证书并在tomcat配置https服务(一) 双向认证: 我们上边生成了服务端证书,并发送给客户端进行了验证. 双向认证是双向的,因此还差客户端证书. 1.为方便导入浏览器,生成p ...
- 用keytool制作证书并在tomcat配置https服务(一)
https分为单项认证和双向认证. 一般https页面上的访问都是单项认证,服务端发送数字证书给客户端,客户单方面验证.而服务端不做验证. 而双向认证,需要双方都有证书,然后发送给对方进行验证.一般用 ...
- 用keytool制作证书并在tomcat配置https服务(四)
用keytool制作证书并在tomcat配置https服务(一) 用keytool制作证书并在tomcat配置https服务(二) 用keytool制作证书并在tomcat配置https服务(三) 上 ...
- 用keytool制作证书并在tomcat配置https服务(三)
用keytool制作证书并在tomcat配置https服务(一) 用keytool制作证书并在tomcat配置https服务(二) 用keytool制作证书并在tomcat配置https服务(四) 模 ...
- tomcat添加https服务
系统环境: centos6.7 jdk-7u79-linux-x64 apache-tomcat-7.0.57 apr-1.5.2 apr-util-1.5.4 一.tomcat安装 自己准备tomc ...
- 使用poco 的NetSSL_OpenSSL 搭建https 服务端,使用C++客户端,java 客户端访问,python访问(python还没找到带证书访问的代码.)
V20161028 由于项目原因,需要用到https去做一些事情. 这儿做了一些相应的研究. 这个https 用起来也是折腾人,还是研究了一周多+之前的一些积累. 目录 1,java client 通 ...
- centos7.x下环境搭建(五)—nginx搭建https服务
https证书获取 十大免费SSL证书 https://blog.csdn.net/ithomer/article/details/78075006 如果我们用的是阿里云或腾讯云,他们都提供了免费版的 ...
- Eclipse+Tomcat搭建https环境
一.首先在本地建立一个keystore文件 用命令:keytool -v -genkey -alias tomcat -keyalg RSA -keystore c:/tomcat.keystore ...
- tomcat开启https服务
一.创建证书 证书是单点登录认证系统中很重要的一把钥匙,客户端于服务器的交互安全靠的就是证书:本教程由于是演示所以就自己用JDK自带的keytool工具生成证书:如果以后真正在产品环境中使用肯定要去证 ...
随机推荐
- Eclipse 中 SVN 提交过滤
- python全栈学习笔记(三)网络基础之网络设备及架构介绍
- eclipse中对Hadoop项目进行mvn clean install时报错的处理
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-clean-plugin:2.5:clean (default-clean) ...
- xise官方网站|xise最新版下载|-xise
诠释: 1. 破解VIP登陆限制 2.去后门 (自查) 下载地址 :https://pan.baidu.com/s/1eR2rUOM 查毒地址:http://a.virscan.org/a3983f3 ...
- How to update BOL entity property value via ABAP code
Suppose I have one product with ID I042416 which could be found in CRM WebClient UI: I would like to ...
- OC Nsstring的使用
// // main.m // NSString // // Created by mj on 13-4-5. // Copyright (c) 2013年 itcast. All rights re ...
- MongoDB创建集合、删除集合
创建集合 createCollection() 方法 在 MongoDB 中,创建集合采用 db.createCollection(name, options) 方法. 语法格式 createColl ...
- 【[JLOI2013]卡牌游戏】
思路太妙了 刚开始yy出了一种比较自然的dp方法,就是按照游戏的进行来开始dp,设\(dp[i][j]\)表示第\(i\)个人为庄家,还剩下\(j\)个人的概率为多少,但是很快发现这个样子没法转移,因 ...
- Cow Relays 【优先队列优化的BFS】USACO 2001 Open
Cow Relays Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Tota ...
- Entity Framework——性能测试
内容提要 一.对EF框架的性能测试 增.删.改,查测试及性能优化 二.使用sql执行 增.删.改,查测试 三.对以上两种方式对比分析 一 对EF框架的测试 1插入操作测试 测试代码(关键部分) Lis ...