Rails 3.1, Unicorn and Apache: static files

余生颓废 提交于 2019-12-21 01:49:10

问题


I have Rails 3.1, Unicorn and Apache setup. My Apache settings are below and production.rb looks like this. I like using h264 streaming but since Rails is serving these video files, the Apache Mod won't 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 have to enable serve_static_assets or I cannot download any static stuff. I have precompiled assets too but it won't make any difference as no file is available from public directory unless Rails (Rack I guess) is doing the serving.

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


回答1:


I have a post for this problem (yeah it also happened to me), hope it will help.

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

Here is my apache server config.

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



回答2:


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 a line with 'X-Sendfile' header, restart your Unicorn's pool and try again.



来源:https://stackoverflow.com/questions/8116170/rails-3-1-unicorn-and-apache-static-files

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!