Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/ruby-on-rails/54.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails Rails 3.1、Unicorn和Apache:静态文件_Ruby On Rails_Apache_Unicorn_Static Files - Fatal编程技术网

Ruby on rails Rails 3.1、Unicorn和Apache:静态文件

Ruby on rails Rails 3.1、Unicorn和Apache:静态文件,ruby-on-rails,apache,unicorn,static-files,Ruby On Rails,Apache,Unicorn,Static Files,我有Rails3.1、Unicorn和Apache设置。下面是我的Apache设置,production.rb看起来像。我喜欢使用h264流媒体,但由于Rails提供这些视频文件,Apache Mod无法工作 DocumentRoot /blabla/current/public RewriteEngine On Options FollowSymLinks <Proxy balancer://unicornservers> BalancerMember http://127

我有Rails3.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
DocumentRoot/blabla/current/public
重新启动发动机
选项如下符号链接
平衡员http://127.0.0.1:4000
#将所有非静态请求重定向到rails
重写cond%{DOCUMENT\u ROOT}/%{REQUEST\u FILENAME}-F
重写规则^/(.*)$balancer://unicornservers%{REQUEST_URI}[P,QSA,L]
ProxyPass/balancer://unicornservers/
ProxyPassReverse/balancer://unicornservers/
代理主机
命令拒绝,允许
通融
上的XSendFile
XSendFileAllowOver打开
我必须启用serve_static_资产,否则我无法下载任何静态内容。我也预编译了资产,但这不会有任何区别,因为公共目录中没有可用的文件,除非Rails(我猜是Rack)正在提供服务


我应该使用config.action\u controller.asset\u主机还是Apache配置有问题。

仅从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池并重试。

我对此问题有一个解决方案(是的,我也遇到过),希望它能有所帮助

关键是要删除
ProxyPass/balancer://unicornservers/
模式,因为它会覆盖您的
重写规则

这是我的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>

ServerName example.org
DocumentRoot/dir/of/your/project
重新启动发动机
#将所有非静态请求重定向到unicorn
重写cond%{DOCUMENT\u ROOT}/%{REQUEST\u FILENAME}-F
重写规则^/(.*)$balancer://unicornservers%{REQUEST_URI}[P,QSA,L]
平衡员http://127.0.0.1:2007

这很有效,谢谢!顺便说一句,你的文章链接指向localhost.perfect,完全有道理,我找到的所有关于Rails3+apache+unicon/thin的指南都有这个问题