在Rails中,我应该启用serve_static_assets吗?

3

我目前使用Apache代理到Thin(使用这个文章)。

我的静态资源都无法正常工作(例如样式表、JavaScript)。Apache应该为它们提供服务还是我需要在config/environments/production.rb中启用config.serve_static_assets?如果Apache应该为它们提供服务,那么我可能做错了什么?

这是我的Apache配置:

<VirtualHost *:80>
  ServerName example.com
  ServerAlias www.example.com

  DocumentRoot /home/r/public_html/example/public

  RewriteEngine On

  <Proxy balancer://thinservers>
    BalancerMember http://127.0.0.1:5000
    BalancerMember http://127.0.0.1:5001
    BalancerMember http://127.0.0.1:5002
  </Proxy>

  # Redirect all non-static requests to thin
  RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f
  RewriteRule ^/(.*)$ balancer://thinservers%{REQUEST_URI} [P,QSA,L]

  ProxyPass / balancer://thinservers/
  ProxyPassReverse / balancer://thinservers/
  ProxyPreserveHost on

  <Proxy *>
    Order deny,allow
    Allow from all
  </Proxy>

  # Custom log file locations
  ErrorLog  /home/r/public_html/example/log/error.log
  CustomLog /home/r/public_html/example/log/access.log combined

</VirtualHost>
1个回答

7

删除以下两行代理指令,它应该就可以工作了:

ProxyPass / balancer://thinservers/
ProxyPassReverse / balancer://thinservers/

第一个重写行(RewriteCond)是用来测试文件在公共目录中是否存在于文件系统中。如果失败,就会继续下一个重写行(RewriteRule),将请求传递给负载均衡代理。这一行实际上和两个代理指令行的作用差不多。
如果测试成功(即静态文件存在),则会跳过此行。如果您删除了上面的两行,则Apache将从文档根目录中提供文件服务。但是,在有上述行的情况下,它还是会将其传递到代理服务器。然后,正如您所指出的那样,Rails默认情况下不会配置为提供此文件,并返回404错误。

糟糕!我忘记了那些代码刚刚创建了一个代理循环。这就是我们按照 2008 年的指示所得到的结果。 - rxgx

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接