今天碰到的一个神奇的问题

今天碰到一个异常奇怪的问题,stage环境的web死活访问不了。

一模一样的代码部署在另一个环境就正常,偏偏到了stage环境就400了。

image.png

唯一看到是来自Tomcat 的INFO级别的报错。

image.png

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
17:27:56.858 [http-nio-8082-exec-2][Http11Processor][] INFO  - The host [crmweb_stage] is not valid
Note: further occurrences of request parsing errors will be logged at DEBUG level.
java.lang.IllegalArgumentException: The character [_] is never valid in a domain name.
at org.apache.tomcat.util.http.parser.HttpParser$DomainParseState.next(HttpParser.java:963)
at org.apache.tomcat.util.http.parser.HttpParser.readHostDomainName(HttpParser.java:859)
at org.apache.tomcat.util.http.parser.Host.parse(Host.java:71)
at org.apache.tomcat.util.http.parser.Host.parse(Host.java:45)
at org.apache.coyote.AbstractProcessor.parseHost(AbstractProcessor.java:294)
at org.apache.coyote.http11.Http11Processor.prepareRequest(Http11Processor.java:759)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:343)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:65)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:860)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1598)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Thread.java:748)

拿着这关键词到谷歌里搜索了一通,确实搜到了Tomcat的一个bug:https://bz.apache.org/bugzilla/show_bug.cgi?id=62371

原因是Spring Boot 升级到2.1.x版本时,Tomcat版本由8.5升级至9.0。新版本的Tomcat不再支持_下划线的域名,而nginx上配置的反向代理upstream名为crmweb_stage

image.png