Domanda

I have the same question as this question but not in an EC2 context, just simply starting my spring boot application from the command line. I managed to get my application running with HTTPS by following the code from this example:

@Profile( "security" )
@Configuration
public class SecurityConfiguration
{
    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer( @Value("${keystore.file}") Resource keystoreFile,
                                                                   @Value("${keystore.pass}") final String keystorePass ) throws IOException
    {
        final String absoluteKeystoreFile = keystoreFile.getFile().getAbsolutePath();

        return new EmbeddedServletContainerCustomizer()
        {
            @Override
            public void customize( ConfigurableEmbeddedServletContainer container )
            {
                TomcatEmbeddedServletContainerFactory tomcat = (TomcatEmbeddedServletContainerFactory)container;
                tomcat.addConnectorCustomizers( new TomcatConnectorCustomizer()
                {
                    @Override
                    public void customize( Connector connector )
                    {
                        connector.setPort( 8443 );
                        connector.setSecure( true );
                        connector.setScheme( "https" );

                        Http11NioProtocol proto = (Http11NioProtocol)connector.getProtocolHandler();
                        proto.setSSLEnabled( true );
                        proto.setKeystoreFile( absoluteKeystoreFile );
                        proto.setKeystorePass( keystorePass );
                        proto.setKeystoreType( "PKCS12" );
                        proto.setKeyAlias( "tomcat" );

                    }
                } );
            }
        };
    }
}

So now I can access my application on https://localhost:8443/.

I would like that http://localhost:8443 would redirect to https. Now Chrome just shows: "No data received" which is not very user friendly.

È stato utile?

Soluzione

AFAIK you can't do that: if Tomcat is listening for HTTPS on port 8443, it can't be listening for HTTP on the same port. The other question you linked to was different in that it wasn't about a specific port.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top