配置Tomcat支持https
主要是两步:
(1)生成证书文件:keytool -genkey -alias tomcat -keyalg RSA -keypass changeit -storepass changeit -keystore server.keystore -validity 3600
(2)为https增加Connector:
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" maxHttpHeaderSize="3500"
?????????????? maxThreads="150" scheme="https" secure="true"
?????????????? clientAuth="false" sslProtocol="TLS" keystoreFile="C:\apache-tomcat-6.0.20\bin\server.keystore" keystorePass="changeit" />
也在网上找到更具体的配置如下,不过我忘了测试成功没.但是前面的那个Connector是肯定可以工作的.
在命令提示符窗口,进入Tomcat目录,执行以下命令:
keytool -genkey -alias tomcat -keyalg RSA -keypass changeit -storepass changeit -keystore server.keystore -validity 3600
通过以上步骤生成server.keystore证书文件
?
将servlet.xml一下的的注释打开(最好拷贝此段)
<!-- Define a SSL HTTP/1.1 Connector on port 8443 -->??
<Connector protocol="org.apache.coyote.http11.Http11Protocol"????
???????????????????? port="8443" maxHttpHeaderSize="8192"??
?????????? maxThreads="150" minSpareThreads="25" maxSpareThreads="75"??
?????????? enableLookups="false" disableUploadTimeout="true"??
?????????? acceptCount="100" scheme="https" secure="true"??
?????????? clientAuth="false" sslProtocol="TLS"???????????????????
?????????? keystoreFile="server.keystore"????
?????????? keystorePass="changeit"/>?
到这一步访问https;//ip:8443/item
一般Tomcat默认的SSL端口号是8443,但是对于SSL标准端口号是443,这样在访问网页的时候,直接使用https而不需要输入端口号就可以访问,如https://loalhost/webserver
想要修改端口号,需要修改Tomcat的server.xml文件:
1.non-SSL HTTP/1.1 Connector定义的地方,一般如下:
???? <Connector port="80" maxHttpHeaderSize="8192"
??????????????? maxThreads="500" minSpareThreads="25" maxSpareThreads="75"
??????????????? enableLookups="false" redirectPort="443" acceptCount="100"
??????????????? connectionTimeout="20000" disableUploadTimeout="true" />
将其中的redirectPort端口号改为:443
2.SSL HTTP/1.1 Connector定义的地方,修改端口号为:443,如下:
<Connector????
?? port="443" maxHttpHeaderSize="8192"
?? maxThreads="150" minSpareThreads="25"
?? maxSpareThreads="75"
?? enableLookups="false"
?? disableUploadTimeout="true"
?? acceptCount="100" scheme="https"
?? secure="true"
?? clientAuth="false" sslProtocol="TLS"
?? keystoreFile="conf/tomcat.keystore"
?? keystorePass="123456" />
3.AJP 1.3 Connector定义的地方,修改redirectPort为443,如下:
???? <Connector port="8009"
??????????????? enableLookups="false" redirectPort="443" protocol="AJP/1.3" />
重新启动Tomcat就可以了。到这一步可以形成访问方式 http://ip/item
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/hitustc/archive/2009/11/22/4853309.aspx