gpt4 book ai didi

amazon-web-services - 如何避免使用Nginx配置进行AWS ELB健康检查的基本身份验证

转载 作者:行者123 更新时间:2023-12-05 00:14:41 25 4
gpt4 key购买 nike

我在尝试为ELB健康检查实现基本身份验证时遇到麻烦。
我进行了大量搜索以弄清楚nginx文件的配置,以避免出现如下所示的401错误,这是ELB由于基本身份验证而返回的错误
unhealthy in target-group hogehoge due to (reason Health checks failed with these codes: [401])
我试图修改nginx.conf以避免它,但是它不起作用。
下面的代码给我[emerg] "server" directive is not allowed here错误。

http {
server {
location / {
if (!$http_x_forwarded_for) {
auth_basic 'Please enter ID and password';
auth_basic_user_file /usr/src/redmine/.htpasswd;
}
}
}
}

如何通过基本身份验证避免ELB运行状况检查导致的401错误?

谢谢您的帮助。

最佳答案

最简单的方法是为ELB创建位置,例如:

location /elb-status {
access_log off;
return 200;
}

您只需要将 Ping Path更改为 /elb-status
如果您想在测试时在浏览器上看到某些内容,则可能需要更改 content-type,因为默认设置为 application/octet-stream,并且浏览器将提供保存文件的功能,因此类似的方法应该起作用:
location /elb-status {
access_log off;
return 200 'your text goes here';
add_header Content-Type text/plain;
}

如果您要对照用户代理进行检查,可以使用如下所示的方法:
set $block 1;

# Allow all the ELB health check agents.
if ($http_user_agent ~* '^ELB-HealthChecker\/.*$') {
set $block 0;
}
if (!$http_x_forwarded_for) {
set $block 1
}

if ($block = 1) {
auth_basic 'Please enter ID and password';
auth_basic_user_file /usr/src/redmine/.htpasswd;
}

关于amazon-web-services - 如何避免使用Nginx配置进行AWS ELB健康检查的基本身份验证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46500271/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com