快速教您Apache + Tomcat + SSL的配置

來源:互聯網
上載者:User
我的運行環境:Windows2003 Server SP4 + J2SDK1.5.0 + Apache2.0.54 + Tomcat5.5.9 

準備軟體: 

1、安裝 Apache 2.0.54 

2、Tomcat 5.5.14 

3、Jk2連接器(mod_jk2.so) 

一:配置Apache和tomcat 

Apache安裝在d:/Apache2 下,監聽連接埠 80; 

Tomcat在D:/Tomcat51 下,監聽連接埠 8080; 

兩者都以windows 2000服務進行安裝。 

將mod_jk2.so複製到d:/Apache2/modules目錄下: 

1.編輯d:/Apache2/conf/httpd.conf檔案,在LoadModule那一段代碼中添加: 


LoadModule jk2_module modules/mod_jk2.so

2.將AddDefaultCharset ISO-8859-1 改為 AddDefaultCharset GB2312 使Apache自動支援中文顯示; 

3.在“虛擬機器主機配置程式碼片段”中添加:(此段配置可以根據你的實際情況進行修改) 


<VirtualHost *:80>
ServerAdmin linvsfen◎163.com
DocumentRoot
"d:/ Tomcat51/webapps/jsp-examples
ServerName localhost
ErrorLog logs/error_log
CustomLog logs/access_log common
</VirtualHost>

編寫workers2.properties檔案並加入d:/Apache2/conf目錄,內容如下: 


# Usually commented out on
production environments
[logger.apache2]
file=”D:/Apache2/logs/error.log”
level=ERROR
# Provide the basic config needed
[config]
file=D:/Apache2/conf/workers2.properties
debug=1
# Provide the location of shm
file on the Apache web server
[shm]
file=D:/Apache2/conf/jk2.shm
size=1000000

[channel.socket:localhost:8009]
port=8009
host=localhost
#define the worker
[ajp13:localhost:8009]
channel=channel.socket:localhost:8009
# Map the Tomcat examples webapp
to the Web server uri space
[uri:/jsp-examples/*]
[uri:/*.jsp]

編寫一個jsp檔案(sessiontest.jsp),放在d:/Tomcat51/webapps/jsp-examples 下;重新啟動以後,啟動apache和tomcat,訪問http://localhost/jsp-examples/sessiontest.jsp可以訪問。 

二.Tomcat配置上ssl步驟: 

1. 產生伺服器憑證server02.jks和用戶端認證dwp.p12 

2、把server02.jks放到conf目錄下,開啟d:/ tomcat51/conf/server.xml 檔案, 

然後修改server.xml檔案,將注釋掉的內容的注釋去掉和增加認證存放的位置:如下: 


<Connector     
port="8443" maxHttpHeaderSize="8192"
maxThreads="150" minSpareThreads="25"
maxSpareThreads="75"
enableLookups="false"
disableUploadTimeout="true"
acceptCount="100" scheme="https"
secure="true"
clientAuth="true" sslProtocol="TLS"
keystoreFile="conf/server02.jks"
keystorePass="123456"
truststoreFile="conf/server02.jks"
truststorePass="123456"/>

註:server02.jks是認證存貯檔案 

安裝用戶端認證dwp.p12 

3. 修改Tomcat配置,使其自動啟用SSL 

開啟d:/test/tomcat51/webapps/jsp-examples/WEB_INF/web.xml 檔案,在security-constraint 標籤下,增加如下內容: 


<user-data-constraint>
<description>
Constrain the user data transport
for the whole application
</description>
<transport-guarantee>
CONFIDENTIAL
</transport-guarantee>
</user-data-constraint>
注釋掉<auth-constraint>標籤下的內容
<auth-constraint>
<!-- Anyone with one of the
listed roles may access this area -->
<role-name>tomcat</role-name>
<role-name>role1</role-name>
</auth-constraint>
在web-resource-collection 標籤下,增加如下內容:
<url-pattern>/*</url-pattern>

重新啟動Apache和tomcat, 

訪問 http://localhost/jsp-examples/sessiontest.jsp是可是訪問的,這是 

系統提示使用者出示認證,啟用SSL加密通道,SSL建立後, 

返回結果。URL變為https://localhost:8443/jsp-examples/sessiontest.jsp 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.