程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> JAVA編程 >> JAVA編程入門知識 >> 實例講解Apache+tomcat+ssl配置

實例講解Apache+tomcat+ssl配置

編輯:JAVA編程入門知識

      我的運行環境: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:Apache2modules目錄下:
   
      1.編輯d:Apache2confhttpd.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:Apache2conf目錄,內容如下:
     
    # 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:Tomcat51webappsjsp-examples 下;

      重新啟動以後,啟動apache和tomcat,訪問http://localhost/jsp-examples/sessiontest.jsp可以訪問。

      二.Tomcat配置上ssl步驟:

      1.    生成服務器證書server02.jks和客戶端證書dwp.p12

      2、把server02.jks放到conf目錄下,

      打開d: tomcat51confserver.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="confserver02.jks"     keystorePass="123456"
                truststoreFile="confserver02.jks" truststorePass="123456"/>
      注:server02.jks是證書存貯文件

      3. 安裝客戶端證書dwp.p12

      3. 修改Tomcat配置,使其自動啟用SSL
     
      打開d: est omcat51webappsjsp-examplesWEB_INFweb.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


 
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved