2015-09-28 65 views
10

WebアプリケーションでSSLを設定しました。必要な手順に従ってTomcatに証明書をインストールしました。私は、次のされていますApache Tomcatのhttpからhttpsへの301のリダイレクトを実行します。

チュートリアルでは、私は、HTTPへの要求がhttpsに転送されることを意味し、HTTP経由でのHTTPSの使用を強制している https://www.mulesoft.com/tcat/tomcat-security

です。次のようにweb.xmlファイルの変更があるhttps://www.mulesoft.com/tcat/tomcat-security#sthash.6zIVA27x.dpuf

:しかし

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

、リダイレクト私はでより多くを参照してください

    • <Connector port="8080" protocol="HTTP/1.1" 
      
            connectionTimeout="20000" 
      
            redirectPort="443" 
      
            proxyHost="10.1.1.1" proxyPort="80" 
      
            URIEncoding="UTF-8" 
      
            maxHttpHeaderSize="32768"/> 
      

      私のserver.xmlの次の変更を行いましたそれは起こっている一時的なリダイレクトすなわち302. 私は301リダイレクト、すなわち、永久リダイレクトを使用したいです。

      どうすれば実現できますか?

  • +0

    この質問に対する回答を見つけましたか?私は同じ問題を抱えています。 – Thermometer

    +0

    同じですが、問題の進捗状況はありますか? – Default71721

    +0

    Googleの「https tomcat」、「always https tomcat」などを実行したい場合は、これが解決策です。 https://jelastic.zendesk.com/hc/en-us/community/posts/206121996-HTTP-HTTPS-redirection-into-the-Tomcatにも解決策があります。 – koppor

    答えて

    2

    これはレルムに設定されています。特定のRealm実装のtransportGuaranteeRedirectStatus属性を参照してください。

    https://tomcat.apache.org/tomcat-8.5-doc/config/realm.html

    例:あなたは、それは301を使用したい場合はserver.xmlには、このアウト・オブ・ボックス

    <Realm className="org.apache.catalina.realm.LockOutRealm"> 
        <!-- This Realm uses the UserDatabase configured in the global JNDI 
         resources under the key "UserDatabase". Any edits 
         that are performed against this UserDatabase are immediately 
         available for use by the Realm. --> 
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
          resourceName="UserDatabase"/> 
        </Realm> 
    

    を持っているそれは302にtransportGuaranteeRedirectStatusのでデフォルトを設定していませんトップレベルのレルムにアトリビュートtransportGuaranteeRedirectStatus="301"を追加するだけです(設定に応じてネストされたレルムがない可能性があります)。そしてTomcatを再起動します。

    例:あなたはあなたの設定で定義されたレルムのタグを持っていない場合は

    <Realm className="org.apache.catalina.realm.LockOutRealm" transportGuaranteeRedirectStatus="301"> 
        <!-- This Realm uses the UserDatabase configured in the global JNDI 
         resources under the key "UserDatabase". Any edits 
         that are performed against this UserDatabase are immediately 
         available for use by the Realm. --> 
        <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
          resourceName="UserDatabase" /> 
        </Realm> 
    

    、TomcatはNullRealmを使用するようにデフォルト設定されます。この状況でリダイレクトを無効にする場合は、transportGuaranteeRedirectStatusプロパティでNullRealmを定義するだけで済みます。

    希望に役立ちます!

    関連する問題