2011-11-14 33 views
8

我有Rails 3.1,Unicorn和Apache安裝程序。我的Apache設置如下,production.rb看起來像this。我喜歡使用h264流媒體,但由於Rails正在提供這些視頻文件,因此Apache Mod將無法工作。Rails 3.1,Unicorn和Apache:靜態文件

DocumentRoot /blabla/current/public 

RewriteEngine On 
Options FollowSymLinks 

<Proxy balancer://unicornservers> 
    BalancerMember http://127.0.0.1:4000 
</Proxy> 

# Redirect all non-static requests to rails 
RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f 
RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L] 

ProxyPass/balancer://unicornservers/ 
ProxyPassReverse/balancer://unicornservers/ 
ProxyPreserveHost on 

<Proxy *> 
Order deny,allow 
Allow from all 
</Proxy> 

XSendFile On 
XSendFileAllowAbove on 

我必須啓用serve_static_assets或我無法下載任何靜態內容。我也預先編譯過資產,但它沒有任何區別,因爲除非Rails(Rack I guess)正在提供服務,否則公共目錄中沒有可用的文件。

我應該使用config.action_controller.asset_host還是我的Apache配置有問題?

回答

19

我有一個post這個問題(是的,它也發生在我身上),希望它會有所幫助。

的關鍵是去除ProxyPass/balancer://unicornservers/模式,因爲它會覆蓋您Rewrite Rule

這裏是我的Apache服務器的配置。

<VirtualHost *:80> 

    ServerName example.org 
    DocumentRoot /dir/of/your/project 

    RewriteEngine On 

    # Redirect all non-static requests to unicorn 
    RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f 
    RewriteRule ^/(.*)$ balancer://unicornservers%{REQUEST_URI} [P,QSA,L] 

    <Proxy balancer://unicornservers> 
    BalancerMember http://127.0.0.1:2007 
    </Proxy> 

</VirtualHost> 
+0

這工作,謝謝! btw。您的文章鏈接指向本地主機。 – jiriki

+0

我修復了鏈接,謝謝! – Manic

+1

完美,使完整的感覺,我找到了所有的導軌3 + apache + unicon /瘦有這個問題 – Rob

0

只需從production.rb代碼:

# Specifies the header that your server uses for sending files 
# config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache 
# config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx 

嘗試以取消與「X-SENDFILE」標題行,重新啓動您的獨角獸的池,然後再試一次。

+0

謝謝,但這並沒有幫助。 – jiriki