Target.ResponseCodeMismatch Error due to 301 HTTP Redirect to HTTPS in Elastic Load Balancer Health Checks

0

I've been experiencing error "Target.ResponseCodeMismatch" after redirecting HTTP to HTTPS in ALB. Checking the access.log shows "10.x.xx.345 - - [08/Nov/2023:03:11:20 +0000] "GET / HTTP/1.1" 301 162 "-" "ELB-HealthChecker/2.0" "-"". My application is running good, only the redirect that caused the error during health checks. I tried inserting the following block below in nginx.conf file to handle the redirect but it didn't solve the issue.

location / {
            return 301 https://$host$request_uri;
        }

Any help is appreciated. Thanks guys in advance!

profile picture
Vin
已提问 6 个月前230 查看次数
2 回答
0

Hello.

It's strange that health check access is being redirected in the first place.
First of all, I think it would be better to prevent health check access from being redirected.
Is there a setting in Nginx settings to redirect when accessing the ALB health check path?

profile picture
专家
已回答 6 个月前
profile picture
专家
已审核 6 个月前
  • Thank you Riku for looking into my issue. This is my only redirection "location / { return 301 https://$host$request_uri; }" for http to https.

  • As Gary says, if you redirect to HTTPS with Nginx, a redirect loop will occur. Therefore, I think it is necessary to eliminate redirect settings in Nginx.

  • I've already removed the redirect

  • The ALB health check is a GET request, so if you can confirm that the application is running at least when you access that path, I don't think there will be any problems.

0

Do not use http to https redirect on ngnix. If you want to redirect http to https, create a 2nd listener on the ALB on port 80 and perform the redirect here. There isnt a need to perform this on NGINX. I would remove that

profile picture
专家
已回答 6 个月前
  • Thank you Gary for looking into my issue. I just removed the redirect. I tried creating a page in website with slug "elb-health-check" then I added a block in nginx.conf this "location /elb-health-check { access_log off; return 200; }". Do you think this is an ideal approach to check the actual health of the environment?

您未登录。 登录 发布回答。

一个好的回答可以清楚地解答问题和提供建设性反馈,并能促进提问者的职业发展。

回答问题的准则