每个springboot打包成独立的jar文件,由nginx代理
1.spring boot配置
新建spring boot测试项目
@RestController
public class UserAPI {
@ResponseBody
@GetMapping("/test")
public String Hello() {
return "hello";
}
}
打包jar_test-0.0.1-SNAPSHOT.jar上传至centos服务器
运行nohup java -jar jar_test-0.0.1-SNAPSHOT.jar --server.port=8081 > log1.file 2>&1 &
@RestController
public class UserAPI {
@ResponseBody
@GetMapping("/test")
public String Hello() {
return "hello2";
}
}
打包jar_test-0.0.2-SNAPSHOT.jar上传至centos服务器
运行nohup java -jar jar_test-0.0.2-SNAPSHOT.jar --server.port=8082 > log2.file 2>&1 &
查看运行情况jobs -l
2.nginx配置
修改nginx.conf文件
location = /hello {
proxy_pass http://127.0.0.1:8081/test;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
location = /hello2 {
proxy_pass http://127.0.0.1:8082/test;
proxy_set_header Host $host;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
}
重启nginx
systemctl restart nginx或者service restart nginx
3.访问
http://yourip/hello
http://yourip/hello2
会访问到对应的springboot程序

本文详细介绍了如何将SpringBoot应用打包为独立的jar文件,并通过Nginx进行代理,实现不同端口上的多个SpringBoot应用的访问。通过具体的代码示例和配置步骤,展示了如何在CentOS服务器上部署并运行这些应用。
1302

被折叠的 条评论
为什么被折叠?



