![](/img/trans.png)
[英]502 Bad Gateway when deploying Spring Boot application to Elastic Beanstalk
[英]Deploying Spring Boot app on AWS Elastic Beanstalk — getting 502 error
我知道,这里有很多这样的问题和答案,但没有一个能帮助我。 我尝试在AWS Elastic Beanstalk上安装我的简单Spring Boot应用程序。 有一个限制:它必须使用.jsp
模板,所以它是.war
,而不是.jar
。 如果我在Elastic Beanstalk上使用预定义的Tomcat环境,一切正常,但我的目标是使用Java环境。
当我安装我的应用程序时,其状态正在Degraded
,当我尝试访问该网址时,我变为502。
在当地一切都很完美。
我将application.properties
端口更改为5000,但它没有帮助。 我发现建议对TCP Port 5000 "0.0.0.0/32"
入站使用安全规则,但它没有帮助收集。
这是我的pom.xml
依赖项:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
</dependency>
<dependency>
<groupId>org.apache.tomcat.embed</groupId>
<artifactId>tomcat-embed-jasper</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
application.properties:
spring.mvc.view.prefix=/WEB-INF/view/
spring.mvc.view.suffix=.jsp
server.port=5000
主Java类:
@SpringBootApplication
public class DemowebApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemowebApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(DemowebApplication.class, args);
}
}
AWS错误日志:
2019/05/07 21:04:45 [error] 7827#0: *19 connect() failed (111: Connection refused) while connecting to upstream, client: 91.232.158.8, server: , request: "GET / HTTP/1.1", upstream: "http://127.0.0.1:5000/", host: "my-endpoint-tst.us-east-2.elasticbeanstalk.com"
2019/05/07 21:04:46 [error] 7827#0: *19 connect() failed (111: Connection refused) while connecting to upstream, client: 91.232.158.8, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "my-endpoint-tst.us-east-2.elasticbeanstalk.com", referrer: "my-endpoint-tst.us-east-2.elasticbeanstalk.com/"
我怀疑问题出在我的Tomcat配置上,但我的所有实验都没有帮助。
我有一个类似的问题。 我会将JAR加载到Elastic Beanstalk,当我尝试访问URL时,我会得到具有降级状态的502 Apache错误。 在本地,我被设置为端口8080,但是当我尝试通过我的URL访问它时,我得到了502.我的问题是:
1)我在导出时没有从IDE导出和上传胖.JAR文件。 我知道你说你不能使用.JAR但是只要确保在导出项目时,你也要用它来导出Maven的所有依赖项。
2)这可能比这个答案的第一部分有更大的帮助,但即使我把我的端口放在application.properties中,也没有提到Elastic Beanstalk实例。 我成功完成解决此问题的工作是进入AWS的管理控制台,转到我的Beanstalk实例,然后转到配置选项卡。
在配置选项卡上有一个软件部分,在该子部分中,转到环境属性。 在环境属性的“名称”部分中,输入SERVER_PORT
,对于值部分,输入5000
。 单击“应用”,然后重新启动实例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.