8

我有 Rails 3.1、Unicorn 和 Apache 设置。我的 Apache 设置如下,production.rb 看起来像这样。我喜欢使用 h264 流,但由于 Rails 提供这些视频文件,Apache Mod 将无法工作。

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)正在提供服务。

我应该使用 config.action_controller.asset_host 还是我的 Apache 配置有问题。

4

2 回答 2

19

我有一个关于这个问题的帖子(是的,它也发生在我身上),希望它会有所帮助。

关键是要删除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>
于 2012-02-22T09:37:03.577 回答
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”标头的行,重新启动 Unicorn 的池并重试。

于 2011-11-14T01:13:31.907 回答