zoukankan      html  css  js  c++  java
  • 阿里云服务器结合域名解析部署springboot项目到Tomcat

    一、环境准备

    1.SpringBoot项目改造

    1.1 pom.xml文件

    1.1.1 为了保证配置后不影响本地项目的启动,我们需要去除打包后的war包的内嵌tomcat。

    <dependency>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-web</artifactId>
    		<exclusions>
    			<exclusion>
    				<groupId>org.springframework.boot</groupId>
    				<artifactId>spring-boot-starter-tomcat</artifactId>
    			</exclusion>
    		</exclusions>
    </dependency>
    <dependency>
    		<groupId>org.springframework.boot</groupId>
    		<artifactId>spring-boot-starter-tomcat</artifactId>
    		<scope>provided</scope>
    </dependency>
    

    1.1.2 启动类也需要改造。下面是示例:

    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.boot.builder.SpringApplicationBuilder;
    import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
    import org.springframework.web.WebApplicationInitializer;
    
    @SpringBootApplication
    public class DemoApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
    	@Override
    	protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
    		return application.sources(DemoApplication.class);
    	}
    
    
    	public static void main(String[] args) {
    		SpringApplication.run(DemoApplication.class, args);
    	}
    
    }
    

    2. Tomcat配置

    2.1 下载

    首先去Tomcat官网下载Tomcat,这里采用Tomcat8.5.57。

    2.2 配置

    2.2.1 修改tomcat目录下的conf文件夹下的server.xml文件。

    1.2.1.1 找到

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

    将“8080”修改为“80”,如下:

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

    2.2.1.2 找到

     <Host name="localhost"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">
            <!-- SingleSignOn valve, share authentication between web applications
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
            -->
    
            <!-- Access log processes all example.
                 Documentation at: /docs/config/valve.html
                 Note: The pattern used is equivalent to using pattern="common" -->
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="localhost_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
          </Host>
    

    将Host标签的name属性修改为自己的域名,我这里是“www.jmuyuer.com”,并添加标签(注意:我这里的docBase使用的是相对路径,也就是war包解压后的项目名)。

     <Host name="www.jmuyuer.com"  appBase="webapps"
                unpackWARs="true" autoDeploy="true">
                
            <Context path="" docBase="demo" reloadable="true" crossContext="true"/>
    
            <!-- SingleSignOn valve, share authentication between web applications
                 Documentation at: /docs/config/valve.html -->
            <!--
            <Valve className="org.apache.catalina.authenticator.SingleSignOn" />
            -->
    
            <!-- Access log processes all example.
                 Documentation at: /docs/config/valve.html
                 Note: The pattern used is equivalent to using pattern="common" -->
            <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
                   prefix="localhost_access_log" suffix=".txt"
                   pattern="%h %l %u %t &quot;%r&quot; %s %b" />
    
          </Host>
    

    2.3 启动

    2.3.1 进入到Tomcat目录下的bin文件夹,输入以下命令启动。

    sudo ./startup.sh
    

    输入以下命令关闭。

    sudo ./shutdown.sh
    
  • 相关阅读:
    CI 知识 :Git介绍及常用操作
    虚拟机的迁移(热迁移)
    kvm虚拟化网络管理
    Zabbix -----安装
    Mariadb 主从
    keepalived + lvs marster 与 backup 之间的 高可用
    LVS 负载均衡 (VS/DR模式 与 VS/TUN 模式)
    linux下部署tomcat 上线jpress博客系统
    docker (2)---存储、网络(利用docker容器上线静态网站)
    openstack(2) -------RabbitMQ集群部署
  • 原文地址:https://www.cnblogs.com/xusp/p/13560791.html
Copyright © 2011-2022 走看看