2016-11-25 10 views
0

私のアプリケーションでは、tomcatでsslを使用し、ポート8080を使用するとうまく動作します。http://localhost:8080にアクセスすると、https://localhost:8443にリダイレクトされます。tomcat sslリダイレクトループ

私は(など8081,8082、)以外のポート8080を使用して、私は(ETCまたはhttp://localhost:8082、)http://localhost:8081にアクセスするときしかし、それはありませんhttp://localhost:8081に無限のリダイレクトループ(またはhttp://localhost:8082、など)ここで私の

<?xml version='1.0' encoding='utf-8'?> 

<Server port="8005" shutdown="SHUTDOWN"> 

    <!--APR library loader. Documentation at /docs/apr.html --> 
    <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 
    <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --> 
    <Listener className="org.apache.catalina.core.JasperListener" /> 
    <!-- Prevent memory leaks due to use of particular java/javax APIs--> 
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 
    <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html --> 
    <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> 
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 

    <!-- Global JNDI resources 
     Documentation at /docs/jndi-resources-howto.html 
    --> 
    <GlobalNamingResources> 
    <!-- Editable user database that can also be used by 
     UserDatabaseRealm to authenticate users 
    --> 
    <Resource name="UserDatabase" auth="Container" 
       type="org.apache.catalina.UserDatabase" 
       description="User database that can be updated and saved" 
       factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
       pathname="conf/tomcat-users.xml" /> 
    </GlobalNamingResources> 


    <Service name="Catalina"> 

    <Connector port="8081" protocol="HTTP/1.1" 
       connectionTimeout="20000" 
       redirectPort="8443" /> 


      <Connector SSLEnabled="true" clientAuth="false" keyAlias="key" keystoreFile="webapps/ROOT/META-INF/my.keystore" keystorePass="pass" maxThreads="150" port="8443" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS"/> 


    <!-- Define an AJP 1.3 Connector on port 8009 --> 
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 


    <Engine name="Catalina" defaultHost="localhost"> 

     <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
      resourceName="UserDatabase"/> 

     <!-- Define the default virtual host 
      Note: XML Schema validation will not work with Xerces 2.2. 
     --> 
     <Host name="localhost" appBase="webapps" 
      unpackWARs="true" autoDeploy="true" 
      xmlValidation="false" xmlNamespaceAware="false"> 


     </Host> 
    </Engine> 
    </Service> 
</Server> 

と8080

<?xml version='1.0' encoding='utf-8'?> 

<Server port="8005" shutdown="SHUTDOWN"> 

    <!--APR library loader. Documentation at /docs/apr.html --> 
    <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> 
    <!--Initialize Jasper prior to webapps are loaded. Documentation at /docs/jasper-howto.html --> 
    <Listener className="org.apache.catalina.core.JasperListener" /> 
    <!-- Prevent memory leaks due to use of particular java/javax APIs--> 
    <Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener" /> 
    <!-- JMX Support for the Tomcat server. Documentation at /docs/non-existent.html --> 
    <Listener className="org.apache.catalina.mbeans.ServerLifecycleListener" /> 
    <Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener" /> 

    <!-- Global JNDI resources 
     Documentation at /docs/jndi-resources-howto.html 
    --> 
    <GlobalNamingResources> 
    <!-- Editable user database that can also be used by 
     UserDatabaseRealm to authenticate users 
    --> 
    <Resource name="UserDatabase" auth="Container" 
       type="org.apache.catalina.UserDatabase" 
       description="User database that can be updated and saved" 
       factory="org.apache.catalina.users.MemoryUserDatabaseFactory" 
       pathname="conf/tomcat-users.xml" /> 
    </GlobalNamingResources> 


    <Service name="Catalina"> 

    <Connector port="8080" protocol="HTTP/1.1" 
       connectionTimeout="20000" 
       redirectPort="8443" /> 


      <Connector SSLEnabled="true" clientAuth="false" keyAlias="key" keystoreFile="webapps/ROOT/META-INF/my.keystore" keystorePass="pass" maxThreads="150" port="8443" protocol="HTTP/1.1" scheme="https" secure="true" sslProtocol="TLS"/> 


    <!-- Define an AJP 1.3 Connector on port 8009 --> 
    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" /> 


    <Engine name="Catalina" defaultHost="localhost"> 

     <Realm className="org.apache.catalina.realm.UserDatabaseRealm" 
      resourceName="UserDatabase"/> 

     <!-- Define the default virtual host 
      Note: XML Schema validation will not work with Xerces 2.2. 
     --> 
     <Host name="localhost" appBase="webapps" 
      unpackWARs="true" autoDeploy="true" 
      xmlValidation="false" xmlNamespaceAware="false"> 


     </Host> 
    </Engine> 
    </Service> 
</Server> 

とここに私のserver.xmlでのserver.xmlは、誰も私を助けることができますか?

私は、(それがserver.xmlの隣のtomcat/confフォルダにする必要があります)しようとするもう一つは、デフォルトのweb.xmlに、強制的にすべてのアプリケーションのためにHTTPSを有効にすることですTomcatの6

答えて

1

を使用していますそれに以下を追加して :

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

注:は、以下のARP(すなわち、ほとんどのLinuxベースのインストール)を有効にしてTomcatのインスタンスに適用されますが、OPが実行されているように、Tomcatをウィンドウ・ベースARPコネクターはすでに無効になっています(または使用できません)。


あなたはリダイレクトループを取得しない理由のわからないが、あなたの構成で見かけの問題は、あなたが本当に「いるkeystoreFile」では動作しません有効APR(ネイティブ)SSLコネクタを、持っているということですので、あなたあなたのログにそのようなエラーメッセージを取得する必要があります。

java.lang.Exception: Connector attribute SSLCertificateFile must be defined when using SSL with APR 

とSSLは関係なく、使用するポート番号の、すべてであなたのために機能してはいけません。 Tomcatが代わりにJSSEコネクタの実装を使用するために

<!-- <Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on" /> --> 

そして、それを倒すための最も簡単な方法は、4月のリスナーをコメントアウトすることです。

+0

ありがとうございました。私はログにポート8080もポート8081も使用していません。私のアプリケーションはポート8080のsslでうまく動作します。しかし、私はAPRリスナーもテストしていますが、変更はありません。私はTomcat 6を使用しています。 – user3078383

+0

これはおそらく、最初のケースではARPがインストールされていないと思われます。 TomcatのどのOS /正確なバージョンを実行していますか? あなたの設定はTomcat 6のように見えますが(私は間違っているかもしれません)。 私はTomcat 6(公式のDockerイメージ経由)を自分のconfigで実行しようとしましたが、ARPを無効にしなければならなかったので、デフォルトで有効になっていました。 – zeppelin

+0

また、Tomcatインスタンス(Nginx e.t.c)の前に何かがありますか? – zeppelin