我在ubuntu服务器上部署了我的springboot应用程序,它使用springsecurity进行安全保护。所以,我有一个问题,我只能使用url访问我的应用程序like:https://示例。com:8443. 至于,为什么我要使用8443端口呢?似乎spring security使用8443端口。有什么解决方案可以帮助我访问url为的应用程序吗www.example.com? 我的相关代码如下:
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;
}
}
1条答案
按热度按时间0yycz8jy1#
如果您想访问您的网站而不必指定端口,您需要确保它在默认端口上运行。
默认的安全http(https://)端口是443。
默认的不安全http(http://)端口是80。