Redirect HTTP to HTTPS:PORT in Tomcat

后端 未结 6 829
傲寒
傲寒 2020-12-08 20:33

I have a running tomcat application that already have the following redirection rule from HTTP to HTTPs:



        
6条回答
  •  北海茫月
    2020-12-08 21:28

    The connector configuration you shown does not redirect a specific URL in the way you suppose.

    That configuration acts if you have configured a CONFIDENTIAL transport guarantee for a web application inside that servlet container.

    I mean, if you have deployed any application on that connector, where its web.xml descriptor has a security-constraint as follows:

    
    
        
            Secured
            /*
        
    
        ...
    
        
            CONFIDENTIAL
        
    
    
    

    Then, Tomcat will redirect any matching url-pattern to the configured port in order to use HTTPS as guarantor of confidentiality in transport.

    So, if you want to redirect a specific URL, you have to complement connector's configuration with specific application configuration.

    Edit

    As you suggest in your comment, it could be another step to get this configuration working. Once you have configured http connector as shown, and then configured app as I told you, you only to ensure that your Tomcat server has an HTTPS connector configured, other way redirection won't work.

    To configure this HTTPS connector, you can use a configuration as following:

      
    

    This is a sample configuration where I didn't put some attributes that can be important for you as threads attrs, executors, and so on.

    The most important thing is the KeyStore configuration that you need to serve HTTPS connections. Here you have the official documentation to prepare a java KeyStore for Tomcat to serve HTTPS.

提交回复
热议问题