简体   繁体   中英

Deploying Spring Boot app on AWS Elastic Beanstalk — getting 502 error

I know, there are a lot of such quesions and answers here, but none of them helped me. I try to install my simple Spring Boot app on AWS Elastic Beanstalk. There is a limitation: it must use .jsp templates, so it's .war , not .jar . If I use predefined Tomcat env on Elastic Beanstalk, everything works fine, but my goal is to use Java env.

When I install my app, its status is getting Degraded and I become 502 when trying to reach the url.

Locally everything works perfect.

I changed port in application.properties to 5000, but it didn't help. I found a recommendation to use a security rule for inbound for TCP Port 5000 "0.0.0.0/32" but it didn't help eather.

Here are my pom.xml dependencies:


    <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

Main Java class:

@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 error logs:

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/"

I suspect that problem is with my Tomcat configuration, but all my experiments with it didn't help yet.

I had a similar issue with this. I would load the JAR up to Elastic Beanstalk and when I would try to access the URL, I would get the 502 Apache error with the degraded status. Locally, I was set to port 8080 but when I tried to access it through my URL I was getting the 502. My problem was:

1) I was not exporting and uploading the fat .JAR file from my IDE when I was exporting it. I know you said you cant use .JAR but just make sure when you are exporting your project, you are also exporting all the dependencies from Maven with it.

2) This might be a bigger help than the first part of this answer but even when I was putting my port in the application.properties, it wasn't pulling through to the Elastic Beanstalk instance. What I successfully ended up doing to solve this issue was going into the management console in AWS, going to my Beanstalk instance, and going to the configuration tab.

On the configuration tab there is a section Software and in that subsection, go to the Environment Properties. In the Name section of the environment properties, enter SERVER_PORT and for the value section, enter 5000 . Click apply and let the instance restart.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM