tomcat下配置https方式


【本地HTTPS】
①.<Connector SSLEnabled="true" clientAuth="false" keystoreFile="C:\tool\apache-tomcat-6.0.35\tomcat.keystore" keystorePass="1a2s3d4f5g" maxThreads="150" port="443" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS"/>

②.<login-config>  
    <!-- Authorization setting for SSL -->  
    <auth-method>CLIENT-CERT</auth-method>  
    <realm-name>Client Cert Users-only Area</realm-name>  
    </login-config> 
    <security-constraint>  
        <!-- Authorization setting for SSL -->  
        <web-resource-collection >  
            <web-resource-name >SSL</web-resource-name>  
            <url-pattern>/order/*</url-pattern>  
        </web-resource-collection>  
        <user-data-constraint>  
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>  
        </user-data-constraint>  
    </security-constraint>
修改:1.Tomcat放一個EXE程序;
      2.修改server.xml 2處8443為443、1處上面①;
      3.web底下的web.xml最下面添加如上的②;

 
 
 
 
 
 以下部分為轉載的內容:

Tomcat配置HTTPS方式

Posted on  2012-06-08 14:22  Delei 閱讀(4398) 評論( 4編輯  收藏 

簡要記錄主要步驟備忘

1、進入到jdk下的bin目錄

2、輸入如下指令

keytool -v -genkey -alias tomcat -keyalg RSA -keystore d:/tomcat.keystore  -validity 36500

附:

d:/tomcat.keystore是將生成的tomcat.keystore放到d盤根目錄下。

"-validity 36500含義是證書有效期,36500表示100年,默認值是90

注意若要放到c盤,在win7系統下,需要以管理員身份進入到命令行中進行操作,否則是無法創建tomcat.keystore的。本例放到d盤下。 
如何以管理員身份進入到命令行下呢?開始->搜索框中輸入cmd->等待(注意不回車)->出現cmd.exe->右鍵“以管理員身份運行”即可。

3、輸入keystore密碼

密碼任意,此處以123456為例,要記住這個密碼,之后在進行server.xml配置時需要使用。

4、輸入名字、組織單位、組織、市、省、國家等信息

注意事項:
A、Enter keystore password:此處需要輸入大於6個字符的字符串
B、“What is your first and last name?”這是必填項,並且必須是TOMCAT部署主機的域名或者IP[如:gbcom.com 或者 10.1.25.251],就是你將來要在瀏覽器中輸入的訪問地址
C、“What is the name of your organizational unit?”、“What is the name of your organization?”、“What is the name of your City or Locality?”、“What is the name of your State or Province?”、“What is the two-letter country code for this unit?”可以按照需要填寫也可以不填寫直接回車,在系統詢問“correct?”時,對照輸入信息,如果符合要求則使用鍵盤輸入字母“y”,否則輸入“n”重新填寫上面的信息
D、Enter key password for <tomcat>,這項較為重要,會在tomcat配置文件中使用,建議輸入與keystore的密碼一致,設置其它密碼也可以
l  完成上述輸入后,直接回車則在你在第二步中定義的位置找到生成的文件

5、輸入之后會出現確認的提示

此時輸入y,並回車。此時創建完成keystore。 
進入到D盤根目錄下可以看到已經生成的tomcat.xml

6、進入tomcat文件夾 
找到conf目錄下的sever.xml並進行編輯

7、編輯 
  <Connector port="8443" protocol="HTTP/1.1" SSLEnabled="true" 
     maxThreads="150" scheme="https" secure="true" 
     clientAuth="false" keystoreFile="D:/AppServer/Tomcat/apache-tomcat-6.0.32/conf/tomcat.keystore" 
     keystorePass="deleiguo" sslProtocol="TLS" /> 
注: 
方框中的keystore的密碼,就是剛才我們設置的“123456”.

編輯完成后關閉並保存sever.xml

8、Tomcat啟動成功后,使用https://127.0.0.1:8443 訪問頁面

頁面成功打開即tomcat下的https配置成功。

 

9、應用程序HTTP自動跳轉到HTTPS

在應用程序中web.xml中加入:

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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM