2013-05-17 45 views
1

我有一個用於端口80的apache虛擬主機,它承載一個rails 3 phusion乘客應用程序。我希望應用程序的某些操作切換到https(端口443)。在兩個虛擬主機之間共享一個phusion乘客軌道應用程序的最佳方式是什麼?在HTTP和HTTPS之間共享Rails 3 Phusion乘客部署

現在,我有:

<VirtualHost *:80> 
    ServerName mycompany.com 
    ServerAlias www.mycompany.com 
    RackBaseURI/

    DocumentRoot /home/ubuntu/mycompany/public 
    <Directory /home/ubuntu/mycompany/public > 
    Options FollowSymLinks 
    AllowOverride None 
    Order allow,deny 
    Allow from all 
    </Directory> 
</VirtualHost> 

and 

<VirtualHost _default_:443> 
    ServerName shop.mycompany.com 
    SSLEngine On 

    ProxyPass/http://localhost/ 
    ProxyPassReverse/http://localhost/ 
    ProxyPreserveHost On 

    SSLCertificateFile /etc/ssl/... 
    SSLCertificateKeyFile /etc/ssl/... 
    SSLCertificateChainFile /etc/ssl/... 
</VirtualHost> 

我知道這是不理想的。一定會有更好的辦法。由於開銷,我不希望所有請求都通過https。

邁克

回答

0

我首先想到的是使用的before_filter控制器內。檢查一些動作,然後重定向到HTTPS例如:

class SomeController < ApplicationController 
    before_filter :redirect, :only => [action_list] 

    def redirect 
    redirect_to :protocol => "https://" unless request.ssl? 
    end 
end 

然而,快速搜索後,我發現這非常有用link。它提供了一個更好的解決方案。

希望它回答你的問題!

+0

不幸的是,我試圖解決與Apache的問題。 Apache和mod_rails將爲端口80和443啓動我的應用程序的兩個實例。現在我正在使用mod_proxy在兩者之間進行轉發。我希望有更好的方法。 – mike

+0

啊我看,你正在看阿帕奇水平。這是我第一次看到像你這樣的配置:)。我想知道按照你的方式做它真的很有效率。 – kasperite