2016-07-27 111 views
1

我创建了一个具有自动扩展组的负载均衡器。它工作得很好,直到我申请SSL证书并将流量重定向到HTTPS。负载均衡器运行状况检查为http one,我无法将该检查移至https,因为证书已应用于负载均衡器。所以当前的堆栈是Rails 4.2,操作系统是ubuntu,http entertainer是nginx,我有5个实例在Load Balancer上运行。所以,我创建了nginx的重定向像下面应用AWS SSL证书后的负载均衡健康检查

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; 
} 

有了这些重定向我的网站去下载并在浏览器我有多个重定向的错误。这个问题让我发疯。请帮忙。您的帮助将受到很多赞赏。谢谢

+0

你是说你将后端实例的运行状况检查重定向回ELB端点? (''mydomain.com'在'return 301 mydomain.com $ request_uri;'指向ELB?)那绝对不行。 –

+0

你怎么设置你的Load Balancer列表器 – error2007s

回答

0

很短,有效的解决方案,将工作100%的任何AWS设置。把它放在应用程序控制器中。

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永远不会通过负载平衡器暴露。

+0

Vola!它为我工作。多谢,伙计 :) –

3

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

  1. 更改负载均衡器监听器: http redirection to http and https redirection to https
  2. 改变在Apache的配置一点:

的LoadModule reqtimeout_module模块/ mod_reqtimeout.so
的LoadModule ssl_module模块/ mod_ssl.so
Listen 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网站。这种配置可能对你有所帮助如果你能解决你的问题,请告诉我。

+0

很多其他人也有同样的问题。这里是AWS论坛主题:https://forums.aws.amazon.com/thread.jspa?messageID=715016 – thekosmix

0

像这样的事情在你的nginx的配置应该工作:

server { 
     listen 80; 
     server_name www.example.com; 


     location = /public/health.html { 
      return 200; 
     } 

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