每个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程序