为什么tomcat在使用类似于“something.com-xyz”的url时返回“400 Bad Request”

问题描述 投票:0回答:1

如果主机名以xyx.com-abc结尾,为什么Tomcat版本7.0.88会出现“400 Bad Request”错误代码。

出于测试目的,我们假设在hosts文件中有以下条目

127.0.0.1 hello.hello.hello-erq

我们尝试从curl访问此URL

curl -v hello.hello.hello-er:8080

我们得到以下输出

* Rebuilt URL to: hello.hello.hello-er:8080/
*   Trying 127.0.0.1...
* Connected to hello.hello.hello-er (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: hello.hello.hello-er:8080
> User-Agent: curl/7.49.0
> Accept: */*
>
< HTTP/1.1 400 Bad Request
< Server: Apache-Coyote/1.1
< Transfer-Encoding: chunked
< Date: Thu, 20 Dec 2018 19:53:09 GMT
< Connection: close
<
* Closing connection 0

在网址中使用localhost时我们得到了

 C:\playground\apache-tomcat-7.0.88-windows-x64\apache-tomcat-7.0.88\bin>curl -v localhost:8080
* Rebuilt URL to: localhost:8080/
*   Trying ::1...
*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8080 (#0)
> GET / HTTP/1.1
> Host: localhost:8080
> User-Agent: curl/7.49.0
> Accept: */*
>
< HTTP/1.1 200 OK
< Server: Apache-Coyote/1.1
< Content-Type: text/html;charset=ISO-8859-1
< Transfer-Encoding: chunked
< Date: Thu, 20 Dec 2018 20:00:07 GMT
<

<!DOCTYPE html>

两个测试的所有tomcat配置都是相同的,同样的问题也可以在一个开箱即用的tomcat服务器上复制。

我试图在tomcat-8上复制相同的问题但是这两个url在那里工作得很好。我怎样才能深入挖掘并在7.0.88中找出这个问题的根本原因?

是否有一些额外的日志记录,我可以在此问题上获得更多信息?

或者我唯一留下的是拔毛和升级?

debugging tomcat tomcat7
1个回答
1
投票

Tomcat试图通过在TLD中使用连字符拒绝您的主机名来enforce the domain name specification。这被认为是Tomcat和fixed in 7.0.89 (and versions of Tomcat 8.0.x, 8.5.x and 9.0.x released around the same time)中的一个错误。

所以你似乎只需要一个小版本的凹凸。

© www.soinside.com 2019 - 2024. All rights reserved.