部署在Elastic Beanstalk Java环境上的Spring Boot应用程序返回502 [英] Spring Boot Application deployed on Elastic Beanstalk Java environment returns 502
问题描述
我正在尝试使用AWS的Java配置(而不是其Tomcat配置)在AWS Elastic Beanstalk上部署一个非常简单的Spring Boot应用程序,但是在以下日志中我始终收到502错误:
I'm trying to deploy a very simple Spring Boot application on AWS Elastic Beanstalk using AWS's Java configuration (not their Tomcat configuration), but I keep getting a 502 error with the following log:
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将端口设置为日志似乎想要的值(使用server.port=5000
使用5000),并已验证我的应用程序已在本地主机的该端口上成功运行.
I've tried setting my port via Spring's application.properties to what the log seems to want (5000, using server.port=5000
) and have verified that my application runs successfully on that port on localhost.
这个问题非常相似,除了我要部署一个JAR而不是WAR.在配置Nginx方面似乎缺少了一些东西,我也不知道该如何进行.
This question is very similar, except that I'm deploying a JAR instead of a WAR. It seems like there is something I'm missing regarding configuring Nginx, and I don't know how to proceed.
这是我的Spring应用程序:
Here's my Spring Application:
@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!";
}
}
}
推荐答案
Nginx不知道Spring Boot应用程序在哪个端口上运行. 通过在最后一步中将"server.port = 5000"添加到application.properties或其他建议的方式,使应用程序在Nginx默认重定向到的端口5000上运行:
Nginx doesn't know on which port your spring boot applicaiton is running. Make application run on port 5000 that Nginx redirects to by default by adding "server.port=5000" to application.properties or other suggested ways in the last step:
这篇关于部署在Elastic Beanstalk Java环境上的Spring Boot应用程序返回502的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!