Tomcat总是返回状态码400

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

# yum install tomcat6 # service tomcat6 start 

根据我看过的教程,我现在应该可以看到一个testing页面。

 # 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 ... 

为什么我在这里得到400? 还有什么我需要configuration?

Tomcat总是返回状态码400

因为webapps目录是空的:

 # ls -l /usr/share/tomcat6/webapps/ total 0 

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

要么创build一个虚拟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 

或者…安装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. 

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 

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 

如果你看到这个错误,但你已经存在其他web应用程序已经存在的环境,你可以简单地创build一个ROOT目录 ,然后在里面创build一个零字节的index.html 。 200成功curl后,将很容易返回。