简体   繁体   中英

aws keep returning 502 bad gateway error using python flask

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....

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.

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