Search code examples
spring-bootiptablestomcat8

Not using port in the url


I use spring boot (tomcat embedded) and ssl.

Actually, I need to type the port (8443) in the url to be able to access web applicaiton.

How to be able to use domnain name only?

Something like https://www.bob.com

instead of

https://www.bob.com:8443/

Edit

@Bean
public EmbeddedServletContainerFactory servletContainer() {
    TomcatEmbeddedServletContainerFactory tomcat
            = new TomcatEmbeddedServletContainerFactory() {

        @Override
        protected void postProcessContext(Context context) {
            SecurityConstraint securityConstraint = new SecurityConstraint();
            securityConstraint.setUserConstraint("CONFIDENTIAL");
            SecurityCollection collection = new SecurityCollection();
            collection.addPattern("/*");
            securityConstraint.addCollection(collection);
            context.addConstraint(securityConstraint);
        }
    };
    tomcat.addAdditionalTomcatConnectors(createHttpConnector());
    return tomcat;
}

private Connector createHttpConnector() {
    Connector connector
            = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setScheme("http");
    connector.setSecure(false);
    connector.setPort(8080);
    connector.setRedirectPort(8443);
    return connector;
}

now not need to type port

but if it type bob.com, browser convert to

bob.com:8443


Solution

  • Default port used by browsers for HTTP is 80 and HTTPS is 443. If you run your application on 443 (since you are using HTTPS), you don't have to use the port number, browser will automatically reroute your URL. To change the port number in you spring-boot applicatioN specify server.port property in bootstrap.yml.

    server:
      port: 443