Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chapter 3: webserver-cluster ALB unable to access #116

Open
myysophia opened this issue Jan 10, 2024 · 3 comments
Open

Chapter 3: webserver-cluster ALB unable to access #116

myysophia opened this issue Jan 10, 2024 · 3 comments
Labels

Comments

@myysophia
Copy link

  1. terraform apply
    `
    ....
    Outputs:

alb_dns_name = "terraform-asg-example-1820730563.us-east-2.elb.amazonaws.com"

2. Access the domain name http 504 dig terraform-asg-example-1820730563.us-east-2.elb.amazonaws.com

; <<>> DiG 9.11.4-P2-RedHat-9.11.4-26.P2.el7_9.14 <<>> terraform-asg-example-1820730563.us-east-2.elb.amazonaws.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 12977
;; flags: qr rd ra; QUERY: 1, ANSWER: 3, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 1024
;; QUESTION SECTION:
;terraform-asg-example-1820730563.us-east-2.elb.amazonaws.com. IN A

;; ANSWER SECTION:
terraform-asg-example-1820730563.us-east-2.elb.amazonaws.com. 60 IN A 13.59.44.32
terraform-asg-example-1820730563.us-east-2.elb.amazonaws.com. 60 IN A 3.22.65.52
terraform-asg-example-1820730563.us-east-2.elb.amazonaws.com. 60 IN A 3.137.118.81

;; Query time: 68 msec
;; SERVER: 10.0.2.3#53(10.0.2.3)
;; WHEN: Wed Jan 10 17:25:38 CST 2024
;; MSG SIZE rcvd: 137

curl -I http://terraform-asg-example-1820730563.us-east-2.elb.amazonaws.com/
HTTP/1.1 504 Gateway Time-out
Server: awselb/2.0
Date: Wed, 10 Jan 2024 09:25:58 GMT
Content-Type: text/html
Content-Length: 132
Connection: keep-alive
`

3.Check that the back-end status is ok

image

image

  1. ref repo
    Any help would be appreciated,3q
@MartinDanielyan
Copy link

Same.
Especial part

Render the User Data script as a template

user_data = templatefile("user-data.sh", {
server_port = var.server_port
db_address = data.terraform_remote_state.db.outputs.address
db_port = data.terraform_remote_state.db.outputs.port
})

Cant understand how var share porn from one file to another. Server didn't run. 502

@brikis98
Copy link
Owner

It's hard to say without more details. Usually, if you're getting a 504 from the ALB, here are the steps you can take to troubleshoot:

  1. Are the health checks passing in the target group? In your first screenshot, see the "Health checks" tab. If not, then you need to find out why. E.g., Are you sending health checks to the right port? Path?
  2. Are the web apps running on the EC2 instances? Your second screenshot seems to suggest they are.
  3. Can the ALB send outbound requests? Check its security group to ensure it allows either all outbound requests, or at least TCP requests to the EC2 instances.
  4. Do the EC2 instances allow inbound requests? Check their security group to ensure it allows either all inbound requests, or at least TCP requests from the ALB.
  5. Are the ALB and the EC2 instances in different subnets? If so, check if there are NACLs or Network Firewalls on those subnets that might be limiting traffic. Also, ensure those subnets have proper route tables that allow traffic to be sent between them.

@Arturomtz8
Copy link

I had the same issue, it was solved adding port = var.server_port to aws_lb_target_group.asg in the health_check dictionary:

resource "aws_lb_target_group" "asg" {
  name     = var.alb_name
  port     = var.server_port
  protocol = "HTTP"
  vpc_id   = data.aws_vpc.default.id

  health_check {
    path                = "/"
    protocol            = "HTTP"
    matcher             = "200"
    port                = var.server_port
    interval            = 15
    timeout             = 3
    healthy_threshold   = 2
    unhealthy_threshold = 2
  }
}


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants