jetty-ssl.xml文件配置

jetty.ssl文件

注意:xml頭部文件http://www.eclipse.org/jetty/configure.dtd用來對該文檔格式進行描述,測試該文檔是否爲有效的XML文檔。由於dtd是從http://www.eclipse.org/jetty/configure.dtd上下載下來的,如果網絡不好會導致文件下不下來,啓動項目可能引起dtd文件not found 的錯誤,這樣便無法解析jetty-ssl.xml文件導致項目啓動不了。

<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">

<!-- =============================================================== -->
<!-- Configure SSL for the Jetty Server                              -->
<!-- this configuration file should be used in combination with      -->
<!-- other configuration files.  e.g.                                -->
<!--    java -jar start.jar etc/jetty-ssl.xml                        -->
<!--                                                                 -->
<!--  alternately, add to the start.ini for easier usage             -->
<!-- =============================================================== -->
<Configure id="Server" class="org.eclipse.jetty.server.Server">

  <!-- if NIO is not available, use org.eclipse.jetty.server.ssl.SslSocketConnector -->

  <New id="sslContextFactory" class="org.eclipse.jetty.http.ssl.SslContextFactory">
    <!--KeyStore文件位置 -->
    <Set name="KeyStore"><Property name="jetty.home" default="." />src/main/resources/conf/server.keystore</Set>
    <!--KeyStore的密碼-->
    <Set name="KeyStorePassword">KeyStore的密碼</Set>
    <!--KeyPair的密碼-->
    <Set name="KeyManagerPassword">KeyPair的密碼</Set>
    <!--另一組KeyStore文件位置 -->
    <Set name="TrustStore"><Property name="jetty.home" default="." />src/main/resources/conf/server.keystore</Set>
    <!--KeyStore的密碼-->
    <Set name="TrustStorePassword">OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4</Set>
  </New>

  <Call name="addConnector">
    <Arg>
      <New class="org.eclipse.jetty.server.ssl.SslSelectChannelConnector">
        <Arg><Ref refid="sslContextFactory" /></Arg>
        <Set name="Port">8443</Set>
        <Set name="maxIdleTime">30000</Set>
        <Set name="Acceptors">2</Set>
        <Set name="AcceptQueueSize">100</Set>
      </New>
    </Arg>
  </Call>
</Configure>

下載portecle-1.7 http://download.csdn.net/download/haleyliu123/9981504
這裏寫圖片描述
雙擊portecle.jar
這裏寫圖片描述

如果要試驗繼續進行,我們還需要證書。那怎麼生成證書呢?我這裏推薦一款pfx加密證書神器,鏈接:http://download.csdn.net/download/haleyliu123/9981908

這裏寫圖片描述
這裏寫圖片描述

這裏寫圖片描述
這樣在output目錄下就生成了證書:
這裏寫圖片描述

然後就是用portecle生成keystore
這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述
這裏寫圖片描述

這裏寫圖片描述

最後一步:
1.把keystore文件複製到jetty的etc文件夾去

2.配置jetty-ssl.xml文件

配置3個地方,一個是指定keystore文件路徑,第二個是設置keystore的密碼,第三個是設置keystore裏面keypair的密碼

這裏寫圖片描述

3.激活jetty-ssl.xml文件

在jetty的根目錄下找到start.ini文件,把 “etc/jetty-ssl.xml”前面的#給去掉
這裏寫圖片描述

發佈了170 篇原創文章 · 獲贊 158 · 訪問量 40萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章