|
为了数据的传输安全,绝大多数的web服务器均需要配置https加密传输协议以保证数据的安全,下面记录详细的配置过程:
1.首先需要确保我们的linux系统配置了jdk,因为我们需要使用jdk的keytool工具来生成我们的密钥:
keytool -genkey -alias tomcat -keyalg RSA -keystore /root/tomcat/apache-tomcat-6.0.37/conf/.keystore
生成的.keystore即为我们的密钥,保存在/root/tomcat/apache-tomcat-6.0.37/conf目录下。
2.然后根据提示完成.keystore的生成:
输入keystore密码:
再次输入新密码:
您的名字与姓氏是什么?
[Unknown]: free4lab
您的组织单位名称是什么?
[Unknown]: free4lab
您的组织名称是什么?
[Unknown]: free4lab
您所在的城市或区域名称是什么?
[Unknown]: beijing
您所在的州或省份名称是什么?
[Unknown]: beijing
该单位的两字母国家代码是什么
[Unknown]: CN
CN=free4lab, OU=free4lab, O=free4lab, L=beijing, ST=beijing, C=CN 正确吗?
[否]: y
输入<tomcat>的主密码
(如果和 keystore 密码相同,按回车):
3.完成以上操作之后,我们可以使用: cat conf/.keystore 来查看我们的密钥
4.密钥生成完成之后,修改tomcat下的server.xml文件:
<Connector port="8080" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="8443" />
修改参数=>
<Connector port="80" protocol="HTTP/1.1"
connectionTimeout="20000"
redirectPort="443" />
<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS"/>
-->
去掉注释且修改参数=>
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
maxThreads="150" scheme="https" secure="true"
clientAuth="false" keystoreFile="/root/tomcat/apache-tomcat-6.0.37/conf/.keystore" keystorePass="yourpassword" sslProtocol="TLS" />
(yourpassword即为生成密钥时设置的密码)
<!--
<Connector port="8009" enableLookups="false" protocol="AJP/1.3" redirectPort="8443" />
-->
修改参数=>
<Connector port="8009" enableLookups="false" protocol="AJP/1.3" redirectPort="443" />
5.tomcat的server.xml文件修改完毕之后,继续修改tomcat的web.xml文件,在标记</web-app>前增加以下配置:
<security-constraint>
<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>
6.完成以上所有操作之后我们就可以以https全局访问web服务了,但是此时的密钥并没有经过CA认证,是不受信任的。
|
|
|