Deploying my application at the root in Tomcat(转自StackOverFlow,做记录)


I know that my answer is kind of overlapping with some of the other answer, but this is a complete solution that has some advantages. This works on Tomcat 8:

  1. The main application is served from the root
  2. The deployment of war files through the web interface is maintained.
  3. The main application will run on port 80 while only the admins have access to the managment folders (I realize that *nix systems require superuser for binding to 80, but on windows this is not an issue).

This means that you only have to restart the tomcat once, and after updated war files can be deployed without a problem.

Step 1: In the server.xml file, find the connector entry and replace it with:

<Connector 
    port="8080"
    protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8443" />

<Connector
    port="80"
    protocol="HTTP/1.1"
    connectionTimeout="20000"
    redirectPort="8443" />

Step 2: Define contexts within the <Host ...> tag:

<Context path="/" docBase="CAS">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
<Context path="/ROOT" docBase="ROOT">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
<Context path="/manager" docBase="manager" privileged="true">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>
<Context path="/host-manager" docBase="host-manager" privileged="true">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
</Context>

Note that I addressed all apps in the webapp folder. The first effectively switch the root and the main app from position. ROOT is now on http://example.com/ROOT and the the main application is on http://example.com/. The webapps that are password protected require the privileged="true" attribute.

When you deploy a CAS.war file that matches with the root (<Context path="/" docBase="CAS">you have to reload that one in the admin panel as it does not refresh with the deployment.

Do not include the <Context path="/CAS" docBase="CAS"> in your contexts as it disables the manager option to deploy war files. This means that you can access the app in two ways: http://example.com/ and http://example.com/APP/

Step 3: In order to prevent unwanted access to the root and manager folder, add a valve to those context tags like this:

<Context path="/manager" docBase="manager" privileged="true">
    <WatchedResource>WEB-INF/web.xml</WatchedResource>
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
        addConnectorPort="true"
        allow="143\.21\.2\.\d+;8080|127\.0\.0\.1;8080|::1;8080|0:0:0:0:0:0:0:1;8080"/>
</Context>

This essentially limits access to the admin web app folder to people from my own domain (fake IP address) and localhost when they use the default port 8080 and maintains the ability to dynamically deploy the war files through the web interface.

If you want to use this for multiple apps that are using different IP addresses, you can add the IP address to the connector (address="143.21.2.1").

If you want to run multiple web apps from the root, you can duplicate the Service tag (use a different name for the second) and change the docbase of the <Context path="/" docBase="CAS">to for example <Context path="/" docBase="ICR">.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
### 回答1: ctly to a server means uploading the application files and configuring the server to run the application. 直接部署Web应用程序到服务器意味着上传应用程序文件并配置服务器以运行应用程序。 ### 回答2: Web应用的部署是为使其在服务器上运行而将应用程序文件和其他资源文件放置在适当位置的过程。部署通常包括以下步骤: 1.选择合适的服务器:根据您的需求选择最适合的服务器,例如:云服务器、共享服务器等。 2.安装必要的Web服务器:部署Web应用程序的第一步是确保您在服务器上安装了Web服务器。Web服务器承担着从客户端(浏览器)请求和返回响应的任务。例如:Apache、IIS 、nginx等Web服务器 3.获取Web应用程序文件:可以从本地系统或远程服务器获取Web应用程序资源文件,确保它们都在同一个目录下。 4.设置Web应用程序:为了使Web应用程序正确地运行,您需要编辑Web应用程序的配置文件。这可能包括更新数据库连接信息,设置虚拟主机等。 5.创建数据库:如果Web应用程序需要与数据库交互,那么您需要在服务器上创建相应的数据库并设置相应的授权。 6.部署应用程序:最后将Web应用程序资源文件部署到服务器上的相应目录下,并启动Web服务器,在浏览器中使用URL路径来访问Web应用程序即可。 最后,您需要测试应用程序以确保它在服务器上正常工作。如果测试成功,您可以通过设置DNS等配置将Web应用程序运行在公网上。部署Web应用程序要求小心谨慎,因为任何错误都可能导致应用程序的故障。因此,建议在部署之前使用沙箱进行测试来确保安全性和可靠性。 ### 回答3: Web应用程序是一种常见的应用程序类型,用户可以通过互联网访问该应用程序。部署Web应用程序需要许多步骤,以下是一些关键步骤: 首先,需要选择一个可靠的Web服务器。常见的Web服务器包括Apache、IIS和Nginx等。选择服务器应该基于应用程序的具体需求和限制,例如运行平台、安全性和性能等方面。 接下来,需要准备服务器环境。这通常包括安装操作系统、网络协议和所选Web服务器,并确保服务器安全性以及常见的安全更新已安装。 然后,需要将Web应用程序代码上传到服务器。这通常通过FTP或SSH等传输协议进行。如果应用程序使用数据库,还需要安装和配置数据库服务器。 接下来,需要配置Web服务器以正确地显示应用程序。这包括配置服务器以显示正确的Web页面、启用应用程序所需的设置和插件,并处理程序的请求和响应。 最后,需要对应用程序进行测试。这可以帮助发现任何错误或漏洞,并确保应用程序与所选的服务器和配置兼容。测试可能包括单元测试、端到端测试和负载测试。 总之,部署Web应用程序需要许多步骤和技能。但是,通过按照这些步骤进行,可以确保应用程序在Web上成功部署并安全运行。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值