tomcat部署war包不成功解决方法

今天尝试在阿里云服务器中的tomcat部署项目
在这里插入图片描述

在这里插入图片描述
点击manager App 时页面显示这样,根据上图提示可知原因是cont/tomcat-users.xml 未配置用户名和密码, 所以需要将下面这段配置用户名和密码的代码添加到tomcat-users.xml中

<role rolename="manager-gui"/>
<user username="tomcat" password="tomcat" roles="manager-gui"/>

在这里插入图片描述

保存后重启tomcat,再点击manage app 后提示输入
账号:tomcat
密码:tomcat 即可打开网址
在这里插入图片描述

若出现了403问题,则是因为访问受限了

403 Access Denied
 
You are not authorized to view this page.
 
By default the Manager is only accessible from a browser running on the same machine as Tomcat. If you wish to modify this restriction, you'll need to edit the Manager's context.xml file.
 
If you have already configured the Manager application to allow access and you have used your browsers back button, used a saved book-mark or similar then you may have triggered the cross-site request forgery (CSRF) protection that has been enabled for the HTML interface of the Manager application. You will need to reset this protection by returning to the main Manager page. Once you return to this page, you will be able to continue using the Manager application's HTML interface normally. If you continue to see this access denied message, check that you have the necessary permissions to access this application.
 
If you have not changed any configuration files, please examine the file conf/tomcat-users.xml in your installation. That file must contain the credentials to let you use this webapp.
 
For example, to add the manager-gui role to a user named tomcat with a password of s3cret, add the following to the config file listed above

这时候需要修改
/webapps/manager/META_INF/context.xml文件,将文件中对访问的来源受限设置注释:

<Context antiResourceLocking="false" privileged="true" >
  <!--注释这里,去除对访问权限的设置
    <Valve className="org.apache.catalina.valves.RemoteAddrValve"
         allow="127\.\d+\.\d+\.\d+|::1|0:0:0:0:0:0:0:1" />
         -->
</Context>

在这里插入图片描述

修改后再重新点击Manage App 即可打开管理界面

### 如何在 Tomcat 服务器部署 WAR #### 准备工作 为了成功地将应用程序作为WAR部署Tomcat服务器,需先确认Java环境已正确设置并安装好Tomcat服务[^3]。 #### 安装与配置Tomcat9 - **下载与解压** 获取官方发布的Tomcat压缩,并将其放置于合适的位置进行解压操作。这一步骤可以通过命令行工具完成,例如wget或curl来获取资源文件,接着利用tar命令来进行解压缩处理[^1]。 - **启动Tomcat** 解压完成后,通过`/path/to/tomcat/bin/startup.sh`脚本来启动Tomcat实例。在此之前可能还需要根据实际情况调整一些默认参数设定,比如JVM内存分配等。 - **验证安装** 打开浏览器访问http://localhost:8080(假设未更改默认端口号),如果看到Tomcat欢迎页面,则表示安装无误。 #### 部署WAR - **准备WAR** 确认要部署的应用程序已经被打成标准格式的WAR档案。该文件通常由构建工具如Maven或Gradle自动生成[^2]。 - **上传WAR至webapps目录** 将WAR文件复制到Tomcat安装路径下的`webapps`文件夹内。当Tomcat检测到新的WAR文件时会自动尝试展开它形成相应的Web应用结构[^4]。 - **配置Context (可选)** 如果希望进一步定制化应用上下文路径或其他高级选项,可以编辑位于`conf/context.xml`中的全局配置项或是创建特定于单个应用的context描述符文件。 #### 启动和测试 - **重启Tomcat** 修改任何配置之后都应该重新加载Tomcat以便使改动生效。使用shutdown.sh停止当前进程后再调用startup.sh开启新会话是一个常见做法。 - **访问应用** 浏览器地址栏输入形如 http://yourserverip:port/applicationname 的URL以检验部署成果。这里需要注意替换实际IP地址、监听端口以及目标项目的名称。 ```bash # 示例:重启Tomcat服务 /path/to/tomcat/bin/shutdown.sh /path/to/tomcat/bin/startup.sh ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值