Tomcat 总是返回状态码 400

Dea*_*ean 1 tomcat centos tomcat6

我刚刚在 CentOS 6.3 上安装了 Tomcat。

# yum install tomcat6
# service tomcat6 start
Run Code Online (Sandbox Code Playgroud)

根据我看过的教程,我现在应该能够看到一个测试页面。

# curl -I 127.0.0.1:8080
HTTP/1.1 400 Bad Request
...

# curl -I 127.0.0.1:8080/manager/html
HTTP/1.1 400 Bad Request
...
Run Code Online (Sandbox Code Playgroud)

为什么我在这里得到400?还有什么我需要配置的吗?

qua*_*nta 5

Tomcat 总是返回状态码 400

因为webapps目录是空的:

# ls -l /usr/share/tomcat6/webapps/
total 0
Run Code Online (Sandbox Code Playgroud)

https://issues.apache.org/bugzilla/show_bug.cgi?id=50734

创建一个虚拟ROOT上下文以获得 404 状态:

# mkdir /usr/share/tomcat6/webapps/ROOT

# ls -l /usr/share/tomcat6/webapps/
total 4
drwxr-xr-x 2 root root 4096 Feb 22 07:47 ROOT

# service tomcat6 restart
Stopping tomcat6:                                          [  OK  ]
Starting tomcat6:                                          [  OK  ]

# curl -I localhost:8080
HTTP/1.1 404 Not Found
Server: Apache-Coyote/1.1
Content-Type: text/html;charset=utf-8
Content-Length: 955
Date: Fri, 22 Feb 2013 06:48:06 GMT
Run Code Online (Sandbox Code Playgroud)

或者...安装tomcat6-webapps软件包以获得 200:

yum info tomcat6-webapps

Name        : tomcat6-webapps
Arch        : noarch
Version     : 6.0.24
Release     : 48.el6_3
Size        : 609 k
Repo        : updates
Summary     : The ROOT and examples web applications for Apache Tomcat
URL         : http://tomcat.apache.org/
License     : ASL 2.0
Description : The ROOT and examples web applications for Apache Tomcat.
Run Code Online (Sandbox Code Playgroud)

tree -L 2 /usr/share/tomcat6/webapps/

/usr/share/tomcat6/webapps/
??? examples
?   ??? index.html
?   ??? jsp
?   ??? servlets
?   ??? WEB-INF
??? ROOT
?   ??? asf-logo-wide.gif
?   ??? build.xml
?   ??? favicon.ico
?   ??? index.html
?   ??? index.jsp
?   ??? RELEASE-NOTES.txt
?   ??? tomcat.gif
?   ??? tomcat-power.gif
?   ??? tomcat.svg
?   ??? WEB-INF
??? sample
    ??? hello.jsp
    ??? images
    ??? index.html
    ??? META-INF
    ??? WEB-INF

10 directories, 12 files
Run Code Online (Sandbox Code Playgroud)

curl -I localhost:8080

HTTP/1.1 200 OK
Server: Apache-Coyote/1.1
Accept-Ranges: bytes
ETag: W/"7777-1357565143000"
Last-Modified: Mon, 07 Jan 2013 13:25:43 GMT
Content-Type: text/html
Content-Length: 7777
Date: Fri, 22 Feb 2013 06:52:04 GMT
Run Code Online (Sandbox Code Playgroud)