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工具生成证书:如果以后真正在产品环境中使用肯定要去证 ...
随机推荐
- LSF作业管理系统使用方法
查看LSF计算节点列表bhosts # bhosts HOST_NAME STATUS JL/U MAX NJOBS RUN SSUSP USUSP RSV fat01 ok - 16 0 0 0 0 ...
- _bstr_t可接受多字节、UNICODE字符串,方便用以字符集转换
使用_bstr_t需要包含的头文件: #include <comutil.h> #include <comdef.h> // test.cpp : 定义控制台应用程序的入口点. ...
- Codeforces Round #527 (Div. 3) D2. Great Vova Wall (Version 2) 【思维】
传送门:http://codeforces.com/contest/1092/problem/D2 D2. Great Vova Wall (Version 2) time limit per tes ...
- es6之函数扩展与对象扩展
一.函数扩展 1.参数默认值 参数有默认值,后面不可以再加没有默认值的变量.如以下test函数中,不可以加写成 function test(x,y="word",z){ } fun ...
- 使用cmd命令创建vue(ivieiw)项目
条件,安装好nodejs 第一步:先使用 vue create 命令创建一个项目,等待创建完成. 1.切换目录 2.创建项目 vue create [项目名称] 第二步:切换到项目中. 第三步:使用 ...
- 【题解】洛谷P4391 [BOI2009] Radio Transmission(KMP)
洛谷P4391:https://www.luogu.org/problemnew/show/P4391 思路 对于给定的字符串 运用KMP思想 设P[x]为前x个字符前缀和后缀相同的最长长度 则对于题 ...
- HUD 1288 Hat's Tea(反向的贪心,非常好的一道题)
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1288 Hat's Tea Time Limit: 2000/1000 MS (Java/Others) ...
- git 分支管理方案
现有一般的公司项目均使用git(大多数是gitLab)管理. 开发组 我们的项目都要建立在 开发组的名下 (git.xxcompany.com/xxgroup),除需要公司内部开源的项目,都必须设置为 ...
- 基于kafka rest实现资源访问服务化(实战)
问题引出 新产品的体系架构包含多个模块,模块集特点是数量多.模块间交互复杂.那么统一接口是一个很好的解决方案,为了实现统一接口打算采用微服务的核心思想,设计了采用restful service的数据交 ...
- Linux 常用命令整理
系统 切换用户 su 关机/重新启动 shoutdown,reboot,halt,poweroff 内存数据写入磁盘 sync 查询命令用法 "命令 –help" 或 " ...