aws keep returning 502 bad gateway error using python flask

0 votes

hi I've been trying for over a month on this..

so, I'm trying to test facebook oauth so have an exact copy of flask oauth login sample code which I put in my ec2 instance bought a domain and registered it on route 53, made an application load balancer and assigned my ec2 in it.

the port... I'm using flask default(5000) and security group setting has inbound port 5000(and others I've tried so far - made it for testing anyways) opened and all traffic on outbound. like this

health check is working perfectly fine. I can see from flask log it's working and returning 200.

but when I type in the domain name it's returning 502 bad gateway and I have no clue what's going on... typing in ip address of the ec2 instance works.. on ec2 instance side where I've turned my app on returns code 400 bad request syntax like this - i have no idea why words are cracked tried changing encoding formats and all failed.

so... I've checked security ports, have checked route53 if I assigned my instance on A-type record set correctly, ec2 instance itself seems to work fine, health check from target groups goes all fine, and I'm out of ideas on where i've done wrong. please help me on this....

stuck on one thing for a long time sure is stressful.. :(

EDIT: curl -vvv {domain_name} returns:

* Rebuilt URL to: www.*.xyz/
* Trying 1****...
* TCP_NODELAY set
* Connected to www.*.xyz (*) port 80 (#0)
> GET / HTTP/1.1
> Host: www.*.xyz
> User-Agent: curl/7.53.1
> Accept: */*
>
< HTTP/1.1 502 Bad Gateway
< Server: awselb/2.0
< Date: Wed, 28 Mar 2018 10:43:58 GMT
< Content-Type: text/html
< Content-Length: 138
< Connection: keep-alive
<
<html>
<head>
<title>502 Bad Gateway</title>
</head>
<body bgcolor="white">
<center><h1>502 Bad Gateway</h1></center>
</body>
</html>
* Connection #0 to host www.*.xyz left intact

EDIT2: the reason for my bad gateway error was due to my target group was using https protocol. BUT I need this done with https... since oauth(facebook) only works under https....

Aug 24, 2018 in AWS by bug_seeker
• 15,510 points
12,564 views

2 answers to this question.

0 votes

The 502 Bad Gateway error is an HTTP status code that means that ELB received an invalid response from the EC2 Instance.

I guess you have selected HTTPS in your target group, create a new target group with HTTP and attach it to the load balancer.

Hope this is helpful!

To know more join Master in Python programming course today.

Thanks!

answered Aug 24, 2018 by Priyaj
• 58,020 points
plaese how do you do that?
Hi@matthew,

You need to go in your load balancer, there you can find the target option.
0 votes

The 502 Bad Gateway Error is an indication that something has gone wrong within the server of your application, as opposed to the client side request.

How to Fix a 502 Error

Perform a hard-refresh in your browser. On Macs, this is done by pressing Cmd + Shift + R.

This problem is due to poor IP communication between back-end computers, possibly including the Web server at the site you are trying to visit. Before analysing this problem, you should clear your browser cache completely.

If you get this problem for only some of the Web sites you try to visit then it is likely to be a problem at those sites i.e. one of their pieces of equipment is failing/overloaded. Contact the people at those sites.

If you are surfing the Web and see this problem for all Web sites you try to visit, then either 1) your ISP has a major equipment failure/overload or 2) there is something wrong with your internal Internet connection e.g. your firewall is not functioning correctly. In the first case, only your ISP can help you. In the second case, you need to fix whatever it is that is preventing you reaching the Internet.

In some cases, this error caused by low computer hard disk space, you can go check the free space of your computer hard disk. If there is really not enough free space left, clean your computer hard disk well.

Start your browser in Safe Mode. Running a browser in Safe Mode means to run it with default settings and without add-ons or extensions, including toolbars.

If your web application is configured to listen on a socket, ensure that the socket exists in the correct location and that it has the proper permissions

Finally, restart your computer/networking equipment. Some temporary issues with your computer and how it's connecting to your network could be causing 502 errors, especially if you're seeing the error on more than one website. In these cases, a restart would help.

answered Jan 3, 2019 by iangregor
• 300 points

Related Questions In AWS

0 votes
1 answer
0 votes
1 answer

Nginx error "502 Bad Gateway nginx/1.16.0"

This typically indicates that a back-end service ...READ MORE

answered Jul 4, 2019 in AWS by Isha
8,072 views
0 votes
1 answer
0 votes
1 answer

AWS S3 CLI : error while trying to copy files locally using terminal

For the first error you should add ...READ MORE

answered Aug 3, 2018 in AWS by Archana
• 4,170 points
11,390 views
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer
0 votes
1 answer

502 Bad Gateway Error in CloudFront AWS

To resolve this you have 2 option.    Enable ...READ MORE

answered Sep 6, 2018 in AWS by Priyaj
• 58,020 points
4,398 views
+2 votes
3 answers
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP