ge1mina023
ge1mina023

Reputation: 175

How can I directly use url to access my spring boot web application without any port?

I have deployed my spring boot application which using spring security for security in a ubuntu server.So, I have an problem.I can only access my application with using url like:https://example.com:8443. As for, why do I use the port of 8443?It is seems that spring security using the port of 8443.Is there any solutions help me to access my application with url of www.example.com? my related code is as follows:

spring.freemarker.cache=false
spring.datasource.url=jdbc:mysql://MyIp:3306/keziqu?serverTimezone=UTC
spring.datasource.username=user
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver
server.port=8443
server.ssl.key-store=classpath:**.pfx
server.ssl.key-store-password=password
#server.ssl.key-password=another-secret
logging.file.path=./log/
#logging.level.org.springframework.security=debug
@Configuration
public class TomcatConfig {

    @Bean
    TomcatServletWebServerFactory tomcatServletWebServerFactory() {
        TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory(){
            @Override
            protected void postProcessContext(Context context) {
                SecurityConstraint constraint = new SecurityConstraint();
                constraint.setUserConstraint("CONFIDENTIAL");
                SecurityCollection collection = new SecurityCollection();
                collection.addPattern("/*");
                constraint.addCollection(collection);
                context.addConstraint(constraint);
            }
        };
        factory.addAdditionalTomcatConnectors(createTomcatConnector());
        return factory;
    }

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

Upvotes: 1

Views: 338

Answers (1)

Domenico Sibilio
Domenico Sibilio

Reputation: 1387

If you want to visit your website without having to specify the port, you need to make sure it's running on the default port.

The default secured HTTP (https://) port is 443.

The default unsecured HTTP (http://) port is 80.

Upvotes: 2

Related Questions