如何在没有 webapps 的情况下设置 tomcat 虚拟主机?
我正在尝试将我的web应用程序从resin迁移到Tomcat7。让我困惑的一件事是我不知道如何为一个虚拟主机设置“默认”网络应用程序?
也就是说,我的网站只有一个应用程序:"/"
,位于“/home/destiny/www
”。里面有很多PHP脚本(由apache提供),里面有一个WEB-INF目录,里面有一个标准的JavaEE应用程序。 我的应用程序未打包在 WAR 中,它是默认扩展的
。
我尝试查找有关如何在 tomcat 7 中设置虚拟主机的文档,但所有示例都需要一个“webapps”目录来扩展 WAR,但这不是我的情况!
这是我的 server.xml 设置(tomcat 7.0.23):
<Host name="myhost.com" xmlBase="/home/destiny/www"
unpackWARS="false" autoDeploy="true">
<Context path="/" docBase="." />
</Host>
<!-- default tomcat's host -->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"> ... </Host>
当我启动 tomcat 时,我看到我的 web 应用程序未加载,仅加载了 tomcat 的 web 应用程序(主机管理器、管理器、示例、文档、ROOT ...)。当我打开我的网站时,它显示 tomcat 的默认屏幕(带有损坏的图像)。
配置不起作用...(我尝试了 xmlBase , appBase , docBase ...但都是徒劳的)
似乎一种解决方案是 /home/destiny 中名为 '
目录,但我不想要那个解决方案!我希望我的默认网络应用程序位于 /home/destiny/www 。并且不会安装其他网络应用程序(我不需要 ROOT
' 的 webapp /www/webapps/ROOTwebapps
dir )。
如何解决(在resin中很容易实现)?谢谢。
I am trying to migrate my webapp from resin to Tomcat7 . One thing confuses me is I don't know how to setup a 'default' webapp for one virtual host ?
That is , my site has just one app : "/"
, located in "/home/destiny/www
" . There are many PHP scripts inside (served by apache) , and one WEB-INF directory inside , with a standard JavaEE app. My app is not packaged in WAR , it is default expanded
.
I try to find documents about how to setup a virtual host in tomcat 7 , but all examples need a 'webapps' directory for WARs to expand , but that's not my case !
Here is my server.xml settings (tomcat 7.0.23 ) :
<Host name="myhost.com" xmlBase="/home/destiny/www"
unpackWARS="false" autoDeploy="true">
<Context path="/" docBase="." />
</Host>
<!-- default tomcat's host -->
<Host name="localhost" appBase="webapps"
unpackWARs="true" autoDeploy="true"> ... </Host>
When I start tomcat , I see my webapp not loaded , only tomcat's webapps (host-manager , manager , examples , docs , ROOT ...) loaded. When I open my site , it shows tomcat's default screen (with broken images).
The configuration is not working... ( I tried xmlBase , appBase , docBase ... but all in invain)
It seems one solution is a webapp named 'ROOT
' in /home/destiny/www/webapps/ROOT
directory , but I don't want that solution ! I want my default web app in /home/destiny/www . and there'll be no other webapps installed (I don't need a webapps
dir ).
How to solve it (It's so easy to achieve in resin) ? Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要指向您自己的目录,请尝试以下操作:
转到 tomcat 文件夹
%path_to_tomcat%/conf/Catalina/localhost
如果需要,您也可以将 localhost 更改为您的主机,但如果您唯一要做的就是将应用程序放在“/”上,那么 localhost 就可以了。
在之前定义的文件夹中创建一个名为
ROOT.xml
的文件。在该文件中添加以下内容,另请查看 %path_to_tomcat%/webapps/,如果您不希望默认 tomcat 页面存在,则删除/移动/重命名那里的 ROOT 文件夹。
有关更多详细信息,请参阅方法 #2 @ 此链接 。
To point to your own directory try the following:
go to the tomcat folder
%path_to_tomcat%/conf/Catalina/localhost
You can also change localhost to your host if you want, but if the only thing you are trying to do is get your app on '/' then localhost is fine.
create a file called
ROOT.xml
in the previously defined folder. In that file add the followingAlso look in %path_to_tomcat%/webapps/, and delete/move/rename the ROOT folder that is there if you don't want the default tomcat page to be there.
See the approach #2 @ this link for more details.
这在 Tomcat 7 中适用于我:
这可能不是配置 Tomcat 的最佳方法,但它可以让 Web 应用程序快速运行。
This works for me in Tomcat 7:
It's probably not the best way to configure Tomcat but it gets a webapp working quickly.
这是一个旧线程,但我想分享我的经验,因为它出现在我的搜索结果中。我的问题是升级旧的 JSP 应用程序,这些应用程序在使用 cPanel 和简单的 tomcat 7 安装的新服务器上的文件结构中分解,其中包含子目录。子目录中的文件无法引用其他目录中包含的文件。本质上,Tomcat 为每个子目录创建一个单独的上下文,然后我在包含时收到很多文件未找到错误。
所以我按照马克的建议做了一些改变。我的服务器设置为每个虚拟主机的 Web 文档根设置为 /home/domainuser/public_html ,默认的 tomcat server.xml 将 appbase 和 context docbase 设置为该目录。
所以最终起作用的是“拆分”目录路径并将一部分作为应用程序库,然后将我的上下文的文档库作为 public_html 目录。请参阅下面的示例。
This is sort of an old thread but I wanted to share my experience since this came up in my search results. My issue was upgrading old JSP apps that were exploded in a file structure containing subdirectories on a new server that was using cPanel and an easy tomcat 7 install. Files in subdirectories were not able to reference included files in other directories. Essentially Tomcat was creating a separate context for each subdirectory then I was getting lots of file not found errors on includes.
So I did what Mark suggested with a bit of a change. My server was setup with each virtual host's web document root set to /home/domainuser/public_html and the default tomcat server.xml was setting both the appbase and the context docbase to that directory.
So what finally worked was to "split" up the directory path and put part as the appbase, and then the docbase for my context as the public_html directory. See the example below.