linux部署war包

> 生成war包
项目启动类Application.java 继承 SpringBootServletInitializer并重写configure方法
@SpringBootApplication
public class Application extends SpringBootServletInitializer {
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(Application.class);
    }
}

DemoController.java
@RestController
@RequestMapping("/test")
public class DemoController {
    @RequestMapping("/home")
    public String home() {
        return "DemoController/home";
    }
}

pom.xml文件
<packaging>war</packaging>
<name>java</name>

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-tomcat</artifactId>
    <!--编译和测试时使用,打包不会指定内置tomcat-->
    <scope>provided</scope>
</dependency>

$ mvn clean package -Dmaven.skip.test=True #打包

> war包部署到tomcat
$ vim /usr/local/tomcat/conf/server.xml #tomcat常用配置
<Host name="localhost">
    <Context path="a" docBase="/usr/local/tomcat/webapps/web/java-0.0.1-SNAPSHOT.war"/>
访问项目 172.16.170.2:8081/a 172.16.170.2:8081/a/test

$ vim /usr/local/nginx/conf/nginx.conf #nginx配置域名
http {
    server {
        listen  80;
        server_name webwar.com;

        location /{
            proxy_pass http://localhost:8081/a/;
        }
    }
}
$ /usr/local/nginx/sbin/nginx -s reload #重启nginx
访问项目 webwar.com/test
上一篇:Idea部署web项目到Linux服务器上


下一篇:centos7安装jenkins