【问题标题】:Load Balancer Health Check After Applying AWS SSL certificates应用 AWS SSL 证书后的负载均衡器运行状况检查
【发布时间】:2016-11-30 23:29:57
【问题描述】:

我创建了一个带有自动缩放组的负载平衡器。在我应用 SSL 证书并将流量重定向到 HTTPS 之前,它工作得非常好。负载均衡器运行状况检查是 http 之一,我无法将该检查移至 https,因为证书应用于负载均衡器。所以当前堆栈是 Rails 4.2,操作系统是 ubuntu,http 艺人是 nginx,我有 5 个实例在负载均衡器上运行。所以我在 nginx 上创建了一个重定向,如下所示

if ($scheme = http) {
   return 301 mydomain.com$request_uri;
}

然后我尝试了这个

if ($request_uri != "/public/health.html" ) {
  set $balancer  P;
}
if ($scheme = http) {
  set $balancer  "${balancer}C";
}
if ($balancer = PC) {
  return 303 mydomain.com$request_uri;
}

由于这些重定向,我的网站出现故障,并且在浏览器上我遇到了多次重定向错误。这个问题让我抓狂。请帮忙。您的帮助将不胜感激。谢谢

【问题讨论】:

  • 您是说您将后端实例上的运行状况检查重定向回 ELB 端点吗? (return 301 mydomain.com$request_uri; 中的 mydomain.com 指向 ELB?)这绝对行不通。
  • 您是如何设置负载均衡器侦听器的

标签: ruby-on-rails amazon-web-services ssl nginx amazon-ec2


【解决方案1】:

我的 tomcat 服务器(实例)和 apachae 服务器(负载平衡器)遇到了完全相同的问题。我还在浏览器中获得了多个重定向。我做了两件事:

  1. 更改了负载平衡器侦听器:
  2. 在 apache 配置中稍作更改:

LoadModule reqtimeout_module modules/mod_reqtimeout.so
LoadModule ssl_module 模块/mod_ssl.so
听 443

<VirtualHost *:80>
  <Proxy *>
    Order deny,allow
    Allow from all
    RewriteEngine on
    RewriteCond %{REQUEST_URI} ^/$
    Rewriterule ^(.*)$ https://www.example.com/ [L,R=301]
  </Proxy>

  RequestReadTimeout header=35 body=35

  ProxyPass / http://localhost:8080/ retry=0
  ProxyPassReverse / http://localhost:8080/
  ProxyPreserveHost on

  ErrorLog /var/log/httpd/elasticbeanstalk-error_log
</VirtualHost>

<VirtualHost *:443>

  RequestReadTimeout header=35 body=35

  ProxyPass / http://localhost:8080/ retry=0
  ProxyPassReverse / http://localhost:8080/
  ProxyPreserveHost on

  SSLEngine on
  SSLCertificateFile /path/where/cert/stored/2_example.com.crt
  SSLCertificateKeyFile /path/where/cert/stored/private-key.pem
  SSLCertificateChainFile /path/where/cert/stored/1_root_bundle.crt

  ErrorLog /var/log/httpd/elasticbeanstalk-error_log
</VirtualHost>

我保持端口 80 用于健康检查,443 端口用于站点。此配置可能会对您有所帮助。如果你能解决你的问题,请告诉我。

【讨论】:

【解决方案2】:

非常简短有效的解决方案,可在任何 AWS 设置下 100% 运行。把它放在你的应用程序控制器中。

before_filter :move_to_https if RAILS.env == "production"
def move_to_https
    redirect_to request.url.gsub("http","https") unless request.url.include?("https")
end

这会将任何域流量转换为 https,并且 ip 将永远不会通过负载均衡器公开。

【讨论】:

    【解决方案3】:

    在你的 nginx 配置中这样的东西应该可以工作:

    server {
            listen 80;
            server_name www.example.com;
    
    
            location = /public/health.html {
               return 200;
            }
    
            location / {
                return 301 https://$http_host$request_uri;
            }
        }
    

    【讨论】:

      猜你喜欢
      • 2016-06-09
      • 2019-08-26
      • 1970-01-01
      • 1970-01-01
      • 2020-05-28
      • 1970-01-01
      • 2016-04-05
      • 2017-01-05
      • 1970-01-01
      相关资源
      最近更新 更多