Rails 3.1、Unicorn 和 Apache:静态文件
我有 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 配置有问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我有一个关于这个问题的帖子(是的,它也发生在我身上),希望它会有所帮助。
关键点是删除 ProxyPass / Balancer://unicornservers/ 模式,因为它会覆盖您的重写规则
这是我的 apache 服务器配置。
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 yourRewrite Rule
Here is my apache server config.
仅来自您的 production.rb 代码:
尝试取消注释带有“X-Sendfile”标头的行,重新启动 Unicorn 池并重试。
Just from your production.rb code:
Try to uncomment a line with 'X-Sendfile' header, restart your Unicorn's pool and try again.