tcelvis
tcelvis

Reputation: 167

How to avoid writing explicit port number (8443) in Spring Boot application

I have a Spring Boot application (arbejdsdag.dk) running on a DigitalOcean droplet. I have sucessfully installed a LetsEncrypt SSL certificate and that works too.

However, I am unable to access the site unless I explicitly add the SSL port after the URL.

So: arbejdsdag.dk:8443 works fine arbejdsdag.dk returns a 404 (Not found) error

I also have a redirect from HTTP to HTTPS.

  @Bean
  @Profile("PROD") 
  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(initiateHttpConnector());
    return tomcat;
  }


  @Profile("PROD") 
  private Connector initiateHttpConnector() {
    Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
    connector.setScheme("http");
    connector.setPort(8080);
    connector.setSecure(false);
    connector.setRedirectPort(8443);

    return connector;
  }

The port is set to 8443 in the application properties as pr. the Spring Boot documentation.

server.port=8443

I want to be able to access the site by just typing the URL without having to explicitly adding the port number. What am I missing?

Upvotes: 0

Views: 3142

Answers (1)

Elliott Frisch
Elliott Frisch

Reputation: 201409

The port must be 443 for browsers to use https by default without a port number. Change

server.port=8443

to

server.port=443

But note that you will have to run the application as a privileged user to open a port below 1000 on a *NIX based system.

Upvotes: 2

Related Questions