springboot中内置了很多tomcat的参数,参见
spring-configuration-metadata.json
和 springboot官网中server.tomcat
前缀的一些配置。
不过有些参数没有,比如maxParameterCount
这个参数的配置,所以可以自定义加入想加入的参数到内嵌的tomcat中。
配置个
@Bean
public TomcatConnectorCustomizer tomcatConnectorCustomizer(){
return new TomcatConnectorCustomizer(){
@Override
public void customize(Connector connector) {
connector.setPort(9090);
connector.setMaxParameterCount(20000);
}
}
}
spingboot2.7.x源码参见:
@Bean
TomcatServletWebServerFactory tomcatServletWebServerFactory(
ObjectProvider<TomcatConnectorCustomizer> connectorCustomizers,
ObjectProvider<TomcatContextCustomizer> contextCustomizers,
ObjectProvider<TomcatProtocolHandlerCustomizer<?>> protocolHandlerCustomizers) {
TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
factory.getTomcatConnectorCustomizers()
.addAll(connectorCustomizers.orderedStream().collect(Collectors.toList()));
factory.getTomcatContextCustomizers()
.addAll(contextCustomizers.orderedStream().collect(Collectors.toList()));
factory.getTomcatProtocolHandlerCustomizers()
.addAll(protocolHandlerCustomizers.orderedStream().collect(Collectors.toList()));
return factory;
}
问题描述:nginx配置https后,springboot从request中获取的schema依然是http而不是https。
解决方案:
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_redirect http:// https://; # or $scheme
proxy_set_header X-Forwarded-Proto https; #or $scheme
proxy_set_header Host $http_host;
server.forward-headers-strategy=NATIVE
server.tomcat.redirect-context-root=false
在之前的版本2.1.x中可以添加配置
Enable HTTPS When Running behind a Proxy Server
server.tomcat.remote-ip-header=x-forwarded-for
server.tomcat.protocol-header=x-forwarded-proto