tomcat设置http自动跳转为https访问

简介:

本实验环境:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
[root@localhost conf] # cd /usr/local/tomcat/bin/
[root@localhost bin] # ./version.sh 
Using CATALINA_BASE:    /usr/local/tomcat
Using CATALINA_HOME:    /usr/local/tomcat
Using CATALINA_TMPDIR:  /usr/local/tomcat/temp
Using JRE_HOME:         /usr/java/jdk1 .7.0_75
Using CLASSPATH:        /usr/local/tomcat/bin/bootstrap .jar
Server version: Apache Tomcat /6 .0.41
Server built:   May 19 2014 11:49:25
Server number:  6.0.41.0
OS Name:        Linux
OS Version:     2.6.32-431.el6.i686
Architecture:   i386
JVM Version:    1.7.0_75-b13
JVM Vendor:     Oracle Corporation
[root@localhost bin] #

基于jdk的keytool工具生成key,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
[root@localhost ~] # find / -name keytool
/usr/java/jdk1 .7.0_75 /jre/bin/keytool
/usr/java/jdk1 .7.0_75 /bin/keytool
[root@localhost ~] # cd /usr/java/jdk1.7.0_75/bin/
#/usr/local/tomcat/tomcat.keystore 证书存放位置; -validity 36500证书有效期,36500表示100年,默认值是90天
[root@localhost bin] # ./keytool -genkey -alias tomcat -keyalg RSA -keystore /usr/local/tomcat/tomcat.keystore -validity 36500
Enter keystore password:           #此处需要输入大于6个字符的字符串
Re-enter new password: 
What is your first and last name?     #“您的名字与姓氏是什么?”这是必填项,并且必须是TOMCAT部署主机的域名或者IP[如:pvbutler.blog.51cto.com 或者 10.15.24.254],就是你将来要在浏览器中输入的访问地址
   [Unknown]:  10.15.24.254
What is the name of your organizational unit?    #“你的组织单位名称是什么?”可以按照需要填写也可以不填写直接回车,实验中直接回车
   [Unknown]:  
What is the name of your organization?     #“您的组织名称是什么?”,同上直接回车
   [Unknown]:  
What is the name of your City or Locality?    #“您所在城市或区域名称是什么?,同上直接回车
   [Unknown]:  
What is the name of your State or Province?     #“您所在的州或者省份名称是什么?”
   [Unknown]:  
What is the two-letter country code  for  this unit?     #“该单位的两字母国家代码是什么?”
   [Unknown]:  
Is CN=10.15.24.254, OU=Unknown, O=Unknown, L=Unknown, ST=Unknown, C=Unknown correct?       #系统询问“正确吗?”时,对照输入信息,如果符合要求则使用键盘输入字母“y”,否则输入“n”重新填写上面的信息
   [no]:  y
 
Enter key password  for  <tomcat>   
     (RETURN  if  same as keystore password):     #输入<tomcat>的主密码,这项较为重要,会在tomcat配置文件中使用,建议输入与keystore的密码一致,设置其它密码也可以
Re-enter new password: 
[root@localhost bin] #   #此时会在/usr/local/tomcat中生成文件tomcat.keystore

修改配置tomcat服务器

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
[root@localhost bin] # cd /usr/local/tomcat/conf/
[root@localhost conf] # cp server.xml server.xmlbak
[root@localhost conf] # cp web.xml web.xmlbak
[root@localhost conf] # vim server.xml
  69     <Connector port= "80"  protocol= "HTTP/1.1" 
  70                connectionTimeout= "20000" 
  71                redirectPort= "443"  />    #将redirectPort="8443"修改为redirectPort="443"
  
  83  #去掉注释<!--和-->;修改port="8443"为port="443";指定证书文件的位置和<tomcat>的主密码keystoreFile="/usr/local/tomcat/tomcat.keystore" key    storePass="justin"
  84     <Connector port= "443"  protocol= "HTTP/1.1"  SSLEnabled= "true"
  85                maxThreads= "150"  scheme= "https"  secure= "true"  86                clientAuth= "false"  sslProtocol= "TLS"  keystoreFile= "/usr/local/tomcat/tomcat.keystore"  key    storePass= "justin"  />
  87    
  
  #将redirectPort="8443"修改为redirectPort="443"
  90   <Connector port= "8009"  enableLookups= "false"  protocol= "AJP/1.3"  redirectPort= "443"  />
[root@localhost conf] #  
[root@localhost conf] # vim web.xml 
  4634 
4635     <welcome- file -list>
4636         <welcome- file >index.html< /welcome-file >
4637         <welcome- file >index.htm< /welcome-file >
4638         <welcome- file >index.jsp< /welcome-file >
4639     < /welcome-file-list >
#在文件</welcome-file-list>后面加上以下语句:
4640 <login-config>
4641     <!-- Authorization setting  for  SSL -->
4642     <auth-method>CLIENT-CERT< /auth-method >
4643         <realm-name>Client Cert Users-only Area< /realm-name >
4644         < /login-config >
4645         <security-constraint>
4646             <!-- Authorization setting  for  SSL -->
4647     <web-resource-collection >
4648             <web-resource-name >SSL< /web-resource-name >
4649                     <url-pattern>/*< /url-pattern >
4650                         < /web-resource-collection >
4651                             <user-data-constraint>
4652                                     <transport-guarantee>CONFIDENTIAL< /transport-guarantee >
4653                                         < /user-data-constraint >
4654                                         < /security-constraint >
[root@localhost conf] # service tomcat stop
Using CATALINA_BASE:    /usr/local/tomcat
Using CATALINA_HOME:    /usr/local/tomcat
Using CATALINA_TMPDIR:  /usr/local/tomcat/temp
Using JRE_HOME:         /usr/java/jdk1 .7.0_75
Using CLASSPATH:        /usr/local/tomcat/bin/bootstrap .jar
[root@localhost conf] # service tomcat start
Using CATALINA_BASE:    /usr/local/tomcat
Using CATALINA_HOME:    /usr/local/tomcat
Using CATALINA_TMPDIR:  /usr/local/tomcat/temp
Using JRE_HOME:         /usr/java/jdk1 .7.0_75
Using CLASSPATH:        /usr/local/tomcat/bin/bootstrap .jar
[root@localhost conf] #

上述配置完成后,重启TOMCAT后即可以使用SSL。IE地址栏中可以直接输入地址 “http://” 会自动跳转成为 “https://” ,windows环境类似,可参考修改对应文件。

注意事项:

(1)生成证书的时间,如果IE客户端所在机器的时间早于证书生效时间,或者晚于有效时间,IE会提示“该安全证书已到期或还未生效”

(2)如果IE提示“安全证书上的名称无效或者与站点名称不匹配”,则是由生成证书时填写的服务器所在主机的域名“您的名字与姓氏是什么?”/“What is your first and last name?”不正确引起的

(3)如果AC主机不能通过域名查找,必须使用IP,但是这个IP只有在配置后才能确定,这样证书就必须在AC确定IP地址后才能生成

(4)证书文件只能绑定一个IP地址,假设有10.1.25.250 和 192.168.1.250 两个IP地址,在证书生成文件时,如使用了10.1.25.250,通过IE就只能使用10.1.25.250 来访问AC-WEB,192.168.1.250是无法访问AC-WEB的



本文转自 justin_peng 51CTO博客,原文链接:http://blog.51cto.com/ityunwei2017/1650958,如需转载请自行联系原作者

相关文章
|
4月前
|
Java 应用服务中间件
多项目分接口:在同一Tomcat下使用不同的端口号访问不同的项目。
总而言之,要在同一Tomcat服务器下使用不同端口访问不同项目,关键是通过对server.xml文件的配置创建多个 `<Service>`实例和相应的虚拟主机。这种方法既实现了项目隔离,也有助于优化资源利用率。通过遵循本文的详细说明,很容易地就能满足需求实现多项目分接口。
153 38
|
4月前
|
JSON 安全 网络协议
HTTP/HTTPS协议(请求响应模型、状态码)
本文简要介绍了HTTP与HTTPS协议的基础知识。HTTP是一种无状态的超文本传输协议,基于TCP/IP,常用80端口,通过请求-响应模型实现客户端与服务器间的通信;HTTPS为HTTP的安全版本,基于SSL/TLS加密技术,使用443端口,确保数据传输的安全性。文中还详细描述了HTTP请求方法(如GET、POST)、请求与响应头字段、状态码分类及意义,并对比了两者在请求-响应模型中的安全性差异。
357 20
|
4月前
|
安全 网络协议 算法
HTTP/HTTPS与SOCKS5协议在隧道代理中的兼容性设计解析
本文系统探讨了构建企业级双协议隧道代理系统的挑战与实现。首先对比HTTP/HTTPS和SOCKS5协议特性,分析其在工作模型、连接管理和加密方式上的差异。接着提出兼容性架构设计,包括双协议接入层与统一隧道内核,通过协议识别模块和分层设计实现高效转换。关键技术部分深入解析协议转换引擎、连接管理策略及加密传输方案,并从性能优化、安全增强到典型应用场景全面展开。最后指出未来发展趋势将更高效、安全与智能。
166 1
|
5月前
|
安全 网络安全 数据安全/隐私保护
HTTP 与 HTTPS 协议及 SSL 证书解析-http和https到底有什么区别?-优雅草卓伊凡
HTTP 与 HTTPS 协议及 SSL 证书解析-http和https到底有什么区别?-优雅草卓伊凡
278 3
|
9月前
|
Ubuntu Linux Shell
(已解决)Linux环境—bash: wget: command not found; Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
(已成功解决)Linux环境报错—bash: wget: command not found;常见Linux发行版本,Linux中yum、rpm、apt-get、wget的区别;Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
4242 69
(已解决)Linux环境—bash: wget: command not found; Docker pull报错Error response from daemon: Get https://registry-1.docker.io/v2/: net/http: request canceled
|
7月前
|
网络协议 安全 网络安全
HTTP与HTTPS协议入门
HTTP协议是互联网的基石,HTTPS则是其安全版本。HTTP基于TCP/IP协议,属于应用层协议,不涉及数据包传输细节,主要规定客户端与服务器的通信格式,默认端口为80。
230 25
HTTP与HTTPS协议入门
|
12月前
|
监控 安全 搜索推荐
设置 HTTPS 协议以确保数据传输的安全性
设置 HTTPS 协议以确保数据传输的安全性
|
网络协议 Java 应用服务中间件
tomcat配置域名及HTTPS
tomcat配置域名及HTTPS
|
8月前
|
安全 搜索推荐 网络安全
HTTPS与HTTP:区别及安全性对比
HTTP和HTTPS是现代网络通信中的两种重要协议。HTTP为明文传输,简单但不安全;HTTPS基于HTTP并通过SSL/TLS加密,确保数据安全性和完整性,防止劫持和篡改。HTTPS还提供身份验证,保护用户隐私并防止中间人攻击。尽管HTTPS有额外的性能开销和配置成本,但在涉及敏感信息的场景中,如在线支付和用户登录,其安全性优势至关重要。搜索引擎也更青睐HTTPS网站,有助于提升SEO排名。综上,HTTPS已成为大多数网站的必然选择,以保障用户数据安全和合规性。
581 1
|
10月前
|
Web App开发 Linux 应用服务中间件
【DrissionPage】Linux上如何将https改为http
通过上述步骤,可以在Linux上将DrissionPage从HTTPS改为HTTP。关键在于修改DrissionPage配置、代码中的HTTPS设置、URL以及Web服务器配置,确保所有部分都正确使用HTTP协议。通过合理配置和测试,能够确保系统在HTTP环境下稳定运行。
356 1