小男孩‘自慰网亚洲一区二区,亚洲一级在线播放毛片,亚洲中文字幕av每天更新,黄aⅴ永久免费无码,91成人午夜在线精品,色网站免费在线观看,亚洲欧洲wwwww在线观看

分享

5分鐘內(nèi)搞定 Tomcat 的 SSL 配置

 KyunraWang 2017-09-16


本教程使用 JDK 6 和 Tomcat 7,其他版本類似。

基本步驟:

  1. 使用 java 創(chuàng)建一個 keystore 文件
  2. 配置 Tomcat 以使用該 keystore 文件
  3. 測試
  4. 配置應用以便使用 SSL ,例如 https://localhost:8443/yourApp

1. 創(chuàng)建 keystore 文件

執(zhí)行 keytool -genkey -alias tomcat -keyalg RSA 結(jié)果如下

loiane:bin loiane$ keytool -genkey -alias tomcat -keyalg RSA
Enter keystore password:  password
Re-enter new password: password
What is your first and last name?
  [Unknown]:  Loiane Groner
What is the name of your organizational unit?
  [Unknown]:  home
What is the name of your organization?
  [Unknown]:  home
What is the name of your City or Locality?
  [Unknown]:  Sao Paulo
What is the name of your State or Province?
  [Unknown]:  SP
What is the two-letter country code for this unit?
  [Unknown]:  BR
Is CN=Loiane Groner, OU=home, O=home, L=Sao Paulo, ST=SP, C=BR correct?
  [no]:  yes
 
Enter key password for
    (RETURN if same as keystore password):  password
Re-enter new password: password

這樣就在用戶的主目錄下創(chuàng)建了一個 .keystore 文件

2. 配置 Tomcat 以使用 keystore 文件

打開 server.xml 找到下面被注釋的這段

<!--
<Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true"
    maxThreads="150" scheme="https" secure="true"
    clientAuth="false" sslProtocol="TLS" />
-->

干掉注釋,并將內(nèi)容改為

Connector SSLEnabled="true" acceptCount="100" clientAuth="false"
    disableUploadTimeout="true" enableLookups="false" maxThreads="25"
    port="8443" keystoreFile="/Users/loiane/.keystore" keystorePass="password"
    protocol="org.apache.coyote.http11.Http11NioProtocol" scheme="https"
    secure="true" sslProtocol="TLS" />

3. 測試

啟動 Tomcat 并訪問 https://localhost:8443. 你將看到 Tomcat 默認的首頁。

需要注意的是,如果你訪問默認的 8080 端口,還是有效的。

4. 配置應用使用 SSL

打開應用的 web.xml 文件,增加配置如下:

<security-constraint>
    <web-resource-collection>
        <web-resource-name>securedapp</web-resource-name>
        <url-pattern>/*</url-pattern>
    </web-resource-collection>
    <user-data-constraint>
        <transport-guarantee>CONFIDENTIAL</transport-guarantee>
    </user-data-constraint>
</security-constraint>

將 URL 映射設為 /* ,這樣你的整個應用都要求是 HTTPS 訪問,而 transport-guarantee 標簽設置為 CONFIDENTIAL 以便使應用支持 SSL。

如果你希望關閉 SSL ,只需要將 CONFIDENTIAL 改為 NONE 即可。

官方文檔http://tomcat./tomcat-7.0-doc/ssl-howto.html

    本站是提供個人知識管理的網(wǎng)絡存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點。請注意甄別內(nèi)容中的聯(lián)系方式、誘導購買等信息,謹防詐騙。如發(fā)現(xiàn)有害或侵權內(nèi)容,請點擊一鍵舉報。
    轉(zhuǎn)藏 分享 獻花(0

    0條評論

    發(fā)表

    請遵守用戶 評論公約

    類似文章 更多