nginx反向代理布置项目

springboot项目通过命令运行:

mvn spring-boot:run

ps:这里需要找到项目文件的地方然后cmd,输入:mvc spring-boot:run,运行完之后然后就能访问了

2.直接运行main方法
3.打包运行
打包成jar包

1>导入插件

<build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>

2>先打包:通过命令:mvn package或着在lifecycle中直接打包

命令行:java -jar 什么路径下/xxx.jar

ps:注意这里打完包之后要看包所在的路径,-jar 之后时打包的路径+"/"+打完包后的名字

出现面错误,原来的命令时:java -jar spring-boot-study01-0.0.1-SNAPSHOT.jar

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-CiuJgREn-1574775788908)(D:\总结\spring-boot\命令运行jar包出错.png)]

正确的是:java -jar target/spring-boot-study01-0.0.1-SNAPSHOT.jar

语法是:java -jar 包的路径/打完包的全名

ps:打完包编译文件target下看打包全名:

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-oTLufWtQ-1574775788910)(D:\总结\spring-boot\打包后包的所在处png.png)]

打包成war包

1.加依赖:注意这里tomcat加provided,防止tomcat包打包在war包中

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

2.让启动类继承SpringBootInitializer然后重写configure方法

import org.springframework.boot.Banner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.stereotype.Component;

//@SpringBootApplication

@EnableAutoConfiguration
@ComponentScan
public class SpringBootStudy01Application extends SpringBootServletInitializer {
    public static void main(String[] args) {
        //开启banner启动
        SpringApplication.run(SpringBootStudy01Application.class, args);
        //关闭banner启动
//        SpringApplicationBuilder springApplicationBuilder = new SpringApplicationBuilder(SpringBootStudy01Application.class);
//        springApplicationBuilder.bannerMode(Banner.Mode.OFF).run(args);
    }
    @Override
    protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
        return application.sources(SpringBootStudy01Application.class);
    }
}

3.clear一下然后package

4.结果

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-phGYtBLZ-1574775788911)(D:\总结\spring-boot\打包成war包.png)]

5.放在tomcat下webapps修改下名字为:spring-boot-study01.war

6.进入tomcat的bin下启动程序

在linux中布置项目

创建目录

首先需要创建一个目录,把打成的java项目的jar包放在下面

配置nginx的nginx.config文件

1.进入nginx的conf文件然后
sudo vim nginx.conf

2.在nginx支持的http协议下修改文件为

server{
     listen     81;
     server_name  security.taotao.com;
     location /{
       proxy_pass http://127.0.0.1:8081/;
     }
   }

3.进入sbin目录重新启动nginx让配置文件生效

#这样也能停止nginx但是相当于kill,不给nginx做停止前的处理时间直接杀死
./nginx -s stop

#建议用quit命令完整的停止nginx,因为quit支持nginx停止前做处理工作
./nginx -s quit
./nginx

不想停止但是又想让配置文件生效也可以这样做

./nginx -s reload

上传打包的项目

rz -be

运行项目

java -jar /home/projectjar/security01-0.0.1-SNAPSHOT.jar

访问http://ip:81就能看到

nginx 部署react nginx 部署jar包_jar