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

Sco*_*rch 7 port nginx amazon-web-services spring-boot amazon-elastic-beanstalk

我正在尝试使用AWS的Java配置(而不是他们的Tomcat配置)在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"
Run Code Online (Sandbox Code Playgroud)

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

这个问题非常相似,只是我正在部署JAR而不是WAR.看起来我在配置Nginx方面缺少一些东西,我不知道如何继续.

这是我的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!";
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

Dmi*_*try 11

Nginx不知道您的spring boot应用程序在哪个端口上运行.默认情况下,通过在application.properties或其他建议的方法中添加"server.port = 5000",使应用程序在Nginx重定向到的端口5000上运行:

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


err*_*07s 7

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