我刚刚在 CentOS 6.3 上安装了 Tomcat。
# yum install tomcat6
# service tomcat6 start
根据我看过的教程,我现在应该能够看到一个测试页面。
# 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?我还需要配置其他东西吗?
答案1
Tomcat 总是返回状态代码 400
因为webapps
目录是空的:
# ls -l /usr/share/tomcat6/webapps/
total 0
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
或者...安装该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
答案2
如果你看到这个错误,但你所在的环境中已经存在其他 web 应用,你可以简单地创建根目录, 然后创建一个零字节 index.html里面。成功 curl 后将立即返回 200。