Tomcat, JBoss配置Https :
1.Tomcat
1).用jdk自带的工具keytool生成一个证书keystore即生成key
keytool -genkey -alias tomcat -keyalg RSA -keystore d:\tomcat.keystore
2).将tomcat.keystore放到tomcat安装根目录下
3).Tomcat安装目录下conf/server.xml,添加https端口
server.xm里面有https配置,不过被注释掉了,我们打开注释,按如下配置
<Connector 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="tomcat.keystore" keystorePass="qwerty" keystoreType="jks"/>
4)现在就可以通过https来访问你应用了
比如原来, http://localhost:8080/youapp/
现在可以通过 http://lcoalhost:8443/youapp来访问, 你的应用不需要一点变化。
2.JBOSS
1)把key文件拷贝到jboss安装目录\server\default\conf下
2)和tomca类似,找到jboss安装目录\server\default\deploy\jbossweb-tomcat55.sar\server.xml文件
https配置已经有了,不过被注释掉了,按如下配置即可
去掉注释符号 <!-- 和 -->
<Connector port="8443" address="${jboss.bind.address}"
maxThreads="100" strategy="ms" maxHttpHeaderSize="8192"
emptySessionPath="true"
scheme="https" secure="true" clientAuth="false"
keystoreFile="${jboss.server.home.dir}/conf/tomcat.keystore"
keystorePass="qwerty" sslProtocol = "TLS" />
http转换到https
有些客户希望把自己的站点从HTTP平滑转换到HTTPS,用户不需要将原来的地址改成HTTPS就可以直接访问转换后的SSL HTTP,对IIS而言实现其实比较简单,从Custom Error页面下手就可以了。
IIS如果设置成对某些页面要求SSL,但用户还是使用HTTP访问,那IIS会报错,说”he page must be viewed over a secure channel”,如果IIS设置成要求128bit加密而用户浏览器不能支持,那IIS也会报错,说”The page must be viewed with a high-security Web browser”,这两个错误页面都是由IIS自带的Custom Error页面实现的,分别是403-4.htm和403-5.htm两个文件,我们现在需要做的就是把这两个页面的代码替换成以下部分:
<script language=”javascript”>
function redirecthttps()
{
//非标准端口把hostname改成host
var oldQURL = window.location.hostname + window.location.pathname;
var newQURL = ”https://” + oldQURL;
QURL = window.location.href;
//检查URL中是否包含search string
pos = QURL.indexOf(’?');
if (position > 0)
{
QURL = QURL.substring(pos + 1);
newQURL = newQURL + ”?” + QURL;
}
window.location = newQURL;
}
redirecthttps();
</script>
上面的脚本看起来很完美,但假如客户端浏览器不支持或禁止了javascript怎么办?这时就需要服务器端来发送重定向信息,IIS上也必须修改Custom Error页面,但类型是URL而不是FILE,url上包含这个文件:
以下是:ASP方式
<%
if Request.ServerVariables(”SERVER_PORT”) = 80 then
try
dim qstring
dim httpsurl
qstring = Request.ServerVariables(”QUERY_STRING”)
httpsurl = replace(qstring, ”http”, ”https”)
httpsurl = replace(httpsurl, ”403;”, ”")
httpsurl = replace(httpsurl, ”:80″, ”")
Response.Redirect(httpsurl)
Catch e As Exception
end try
end if
%>
这样子用户在输入http://some.url/ 的时候会被自动重定向到https://some.url/ ,当然如果需要对普通用户再透明一点,那就需要一个受信任的证书。
发表于 @ 2009年03月26日 10:56:00 | 评论( loading... ) | 举报| 收藏