Rails 3.1, Unicorn, and Apache: Static Files

I have Rails 3.1, Unicorn and Apache. My Apache settings are lower, and production.rb looks like this . I like to use h264 streams, but since Rails serves these video files, Apache Mod will not work.

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 

I need to enable serve_static_assets or I cannot load any static things. I also have precompiled assets, but that won't make any difference since the file is not accessible from the public directory if Rails (Rack, I think) is not running the service.

Should I use config.action_controller.asset_host or something is wrong with my Apache configuration.

+8
ruby-on-rails apache static-files unicorn
source share
2 answers

I have a post for this problem (yes, this also happened to me), hope this helps.

The key point is to remove the ProxyPass / balancer://unicornservers/ , because it will override your Rewrite Rule

Here is my apache server configuration.

 <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> 
+19
source share

Just from your production.rb code:

 # 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 

Try to uncomment the line with the heading "X-Sendfile", restart the unicorn pool and try again.

0
source share

All Articles