Tomcat配置https及訪問http自動跳轉至https

來源:互聯網
上載者:User

標籤:http   io   ar   使用   sp   java   for   檔案   on   

一、產生認證步驟


二、配置TOMCAT伺服器

(1)修改  $CATALINA_HOME/conf/server.xml  檔案,修改如下:

    <Connector port="80" protocol="HTTP/1.1" connectionTimeout="20000"     redirectPort="443"     executor="tomcatThreadPool"      enableLookups="false"      useBodyEncodingForURI="true"      URIEncoding="utf-8"      compression="on"      compressionMinSize="2048"      noCompressionUserAgents="gozilla,traviata"      compressableMimeType="text/html,text/xml,text/javascript,text/css,text/plain"    />

(2)去掉注釋且修改參數

    <Connector port="443" protocol="org.apache.coyote.http11.Http11Protocol"     SSLEnabled="true"      maxThreads="150"      scheme="https"      secure="true"      clientAuth="want"      sslProtocol="TLS"      keystoreFile="D:/tomcat.keystore"      keystorePass="123456"      truststoreFile="D:/tomcat.keystore"      truststorePass="123456"      />

注釋:keystoreFile、keystorePass、truststoreFile、truststorePass分別是認證檔案的位置和密碼,在認證檔案產生過程中做了設定

(3)修改參數

<Connector port="8009" protocol="AJP/1.3" redirectPort="443" />

(4)強制HTTPS訪問:開啟$CATALINA_HOME/conf/web.xml,或者在專案檔的web.xml最後增加下面內容:

<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>/*</url-pattern></web-resource-collection><user-data-constraint><transport-guarantee>CONFIDENTIAL</transport-guarantee></user-data-constraint></security-constraint>

上述配置完成後,重啟TOMCAT後即可以使用SSL。IE地址欄中可以直接輸入地址不必輸入“http://” 或者 “https://” ;也可以輸入 “http:// ” 會跳轉成為 “https://” 來登入。





Tomcat配置https及訪問http自動跳轉至https

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.