部署在Elastic Beanstalk Java环境上的Spring Boot应用程序返回502

我试图使用AWS的Javaconfiguration(而不是它们的Tomcatconfiguration)在AWS Elastic Beanstalk上部署一个非常简单的Spring Boot应用程序,但是我一直在用以下日志得到一个502错误:

2016/06/10 02:00:14 [error] 4921#0: *1 connect() failed (111: Connection refused) while connecting to upstream, client: 38.94.153.178, server: , request: "GET /test HTTP/1.1", upstream: "http://127.0.0.1:5000/test", host: "my-single-instance-java-app.us-east-1.elasticbeanstalk.com" 

我已经尝试通过Spring的application.properties设置我的端口到日志似乎想要的(5000,使用server.port=5000 ),并validation我的应用程序在localhost上的该端口上成功运行。

这个问题是非常相似的,除了我部署一个JAR而不是一个WAR。 似乎有什么我错过configurationNginx,我不知道如何进行。

这是我的Spring应用程序:

 @SpringBootApplication public class MyApplication { public static void main(String[] args) { SpringApplication.run(MyApplication.class, args); } @RestController public static class MainController { @RequestMapping("/test") public String testMethod() { return "Method success!"; } } } 

从您的问题描述和安全组设置中,您发送给我的是您的EC2实例的唯一入站端口80已通过防火墙向全世界开放,并且您正在使用端口5000作为您的应用程序。 所以使用我给你的安全规则,它也为你的EC2实例打开了入站端口5000,所以你的应用程序开始工作,没有上述错误。

Nginx不知道你的spring启动应用程序在哪个端口上运行。 使应用程序在Nginx默认重定向的端口5000上运行,方法是在application.properties或其他建议的方法的最后一步添加“server.port = 5000”:

https://pragmaticintegrator.wordpress.com/2016/07/12/run-your-spring-boot-application-on-aws-using-elastic-beanstalk/