Java 如何避免在Spring引导应用程序中写入显式端口号(8443)
我有一个Spring启动应用程序(arbejdsdag.dk)在DigitalOcean droplet上运行。我已经成功地安装了LetsEncrypt SSL证书,而且也可以正常工作 但是,除非在URL之后显式添加SSL端口,否则我无法访问该站点 因此: arbejdsdag.dk:8443工作正常 arbejdsdag.dk返回404(未找到)错误 我还有一个从HTTP到HTTPS的重定向Java 如何避免在Spring引导应用程序中写入显式端口号(8443),java,spring,spring-mvc,ssl,spring-boot,Java,Spring,Spring Mvc,Ssl,Spring Boot,我有一个Spring启动应用程序(arbejdsdag.dk)在DigitalOcean droplet上运行。我已经成功地安装了LetsEncrypt SSL证书,而且也可以正常工作 但是,除非在URL之后显式添加SSL端口,否则我无法访问该站点 因此: arbejdsdag.dk:8443工作正常 arbejdsdag.dk返回404(未找到)错误 我还有一个从HTTP到HTTPS的重定向 @Bean @Profile("PROD") public EmbeddedServle
@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;
}
该端口在应用程序属性中设置为8443,如Spring引导文档中所述
server.port=8443
我希望能够通过只键入URL而不必显式添加端口号来访问该站点。我缺少什么?端口必须是
443
,浏览器在默认情况下使用https而不需要端口号。改变
server.port=8443
到
但请注意,您必须以特权用户身份运行应用程序,才能在基于*NIX的系统上打开低于1000的端口。该端口必须为
443
,浏览器才能在默认情况下使用https,而无需端口号。改变
server.port=8443
到
但请注意,您必须以特权用户身份运行应用程序,才能在基于*NIX的系统上打开低于1000的端口。OK。我现在已更改为443,但由于另一个应用程序使用端口443,我的应用程序无法加载
netstat-tupln
显示Apache2正在443上侦听<代码>tcp6 0:::80::*侦听2481/apache2 tcp6 0:::443:::*侦听2481/apache2有办法解决此问题吗?停止apache2,或更改配置使其成为。确定。我现在已更改为443,但由于另一个应用程序使用端口443,我的应用程序无法加载netstat-tupln
显示Apache2正在443上侦听<代码>tcp6 0:::80::*侦听2481/apache2 tcp6 0::443:::*侦听2481/apache2有办法解决此问题吗?停止apache2,或更改配置以使其成为一个新的配置。