2016-07-27 96 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; 
     } 
    } 
相關問題