Spring Boot with Embedded Tomcat behind AWS ELB - HTTPS redirect

后端 未结 2 676
無奈伤痛
無奈伤痛 2020-12-18 14:56

Running Spring boot application port 8080 on EC2 instance.

AWS ELB configured to redirect

     80 -> 8080
     443 (SSL termination happens here)         


        
相关标签:
2条回答
  • 2020-12-18 15:31

    You will have to instantiate your own EmbeddedServletContainerFactory and set the secure property on the connector for this container to true. After that your Ant matcher rule will work.

    Alternatively, you can check out the Spring Boot source code available on Github, add code for reading a boolean configuration property called server.channel.secure, setting it on the embedded Tomcat connector and submit a pull request for the Spring team to incorporate into the next release.

    0 讨论(0)
  • 2020-12-18 15:37

    Looks like this did the trick:

    @Component
    public class TomcatCustomizer implements EmbeddedServletContainerCustomizer {
    
    @Override
    public void customize(ConfigurableEmbeddedServletContainer container) {
        TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory) container;
        tomcat.addConnectorCustomizers(new TomcatConnectorCustomizer() {
            @Override
            public void customize(Connector connector) {
                connector.setSecure(true);  
            }
        });
    
    }
    

    }

    0 讨论(0)
提交回复
热议问题