Java AWS Server: 502 Bad Gateway nginx/1.8.1

2019-02-15 17:57发布

问题:

I am getting the 502 bad gateway error after uploading my application via eclipse and I don't understand why its happening?

I created a Sample Application through the AWS Elastic Beanstalk Console. Then I loaded the server in eclipse. Afterwards I published it and got the "Environment update completed successfully." message in the EB Console. However when I go to the url, I get a 502 Bad Gateway error. I looked at the logs to see what went wrong however only thing I found is

"failed (111: Connection refused) while connecting to upstream, client: 172.31.11.136, server: , request: "GET /favicon.ico HTTP/1.1", upstream: "http://127.0.0.1:5000/favicon.ico", host: "k*****t.3attvpxcin.us-east-1.elasticbeanstalk.com", referrer: "http://k*****t.3attvpxcin.us-east-1.elasticbeanstalk.com/"

and

"no main manifest attribute, in application.jar"

I don't know what else the error is. Any help will be greatly appreciated

Here is a link to the logs that I fetched from EB Console. https://drive.google.com/file/d/0B_Z-8IMBX2LcMW9yd2xsUTVzNVk/view?usp=sharing

回答1:

When you select Java , as a container then your jar should be an executable jar. i.e if you run using jar command from your console it should fail there as well.

what you should do to resolve it build it using plugin
e.g

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>

        </plugin>
    </plugins>

</build>

this will solve the no manifest in jar issue , you can verify by 1. running jar from command propmpt or 2. open jar in winrar or something and see the content of maifest.mf file

the ngix issue is different



回答2:

Today I solved a similar problem. I had the same error (502 Bad Gateway nginx/1.8.1) when trying to run NodeJS+Docker server app on Elastic Beanstalk. The mistake was in wrong selection of platform type (NodeJS instead of Docker) during creating of environment.