2015-09-28 22 views
10

Skonfigurowałem SSL w mojej aplikacji internetowej. Zainstalowałem certyfikat w moim Tomcat zgodnie z wymaganymi krokami.Wykonaj przekierowanie 301 z http do https w Apache Tomcat

Tutorial że śledzę to https://www.mulesoft.com/tcat/tomcat-security

Mam egzekwowane użycie https za pośrednictwem protokołu HTTP, co oznacza, że ​​każde żądanie HTTP zostanie przekazany na https. Zrobiłem następujące zmiany w moim server.xml

<Connector port="8080" protocol="HTTP/1.1" 

      connectionTimeout="20000" 

      redirectPort="443" 

      proxyHost="10.1.1.1" proxyPort="80" 

      URIEncoding="UTF-8" 

      maxHttpHeaderSize="32768"/> 

Zmiany web.xml są następujące:

<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> 

Jednak przekierowanie ma miejsce tymczasowe przekierowanie, tj. 302. Chcę użyć 301 przekierowania, tzn. stałego przekierowania.

Jak mogę to osiągnąć?

+0

Czy znalazłeś odpowiedź na to pytanie? Mam ten sam problem. – Thermometer

+0

Czy to samo dotyczy postępów w tej kwestii? – Default71721

+0

Dla Googlersów, którzy chcą teraz "egzekwować https tomcat", "zawsze https tomcat" lub podobnie, to jest rozwiązanie. https://jelastic.zendesk.com/hc/en-us/community/posts/206121996-HTTP-HTTPS-redirection-into-the-Tomcat zapewnia również rozwiązanie. – koppor

Odpowiedz

2

Jest to skonfigurowane w Twoim Królestwie. Zobacz atrybut transportGuaranteeRedirectStatus swojej konkretnej implementacji Realm.

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

Ex: server.xml ma to out-of-the-box

<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> 

Nie ustawione transportGuaranteeRedirectStatus więc domyślnie 302. Jeśli chcesz, aby użyć 301 , po prostu dodaj atrybut transportGuaranteeRedirectStatus="301" do dziedziny najwyższego poziomu (możesz nie mieć zagnieżdżonych dziedzin w zależności od konfiguracji) i zrestartuj Tomcat.

Ex:

<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> 

Jeśli nie masz tag Realm zdefiniowanego w konfiguracji, Tomcat będzie domyślnie używając NullRealm. Jeśli chcesz zastąpić przekierowanie w tej sytuacji, wystarczy zdefiniować wartość NullRealm z ustawioną wartością właściwości transportGuaranteeRedirectStatus.

Nadzieję, że pomaga!

Powiązane problemy