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

2024-01-05

我目前正在使用 Apache 代理到 Thin(使用这个article http://articles.slicehost.com/2008/5/6/ubuntu-hardy-apache-rails-and-thin)

我的静态资源都不起作用(例如样式表、javascript)。 Apache 应该为他们提供服务还是我必须启用config.serve_static_assets in config/environments/production.rb?如果 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>

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

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

第一个重写行(RewriteCond) 是查看文件是否存在于公共目录中的文件系统上的测试。如果失败,则继续下一个重写行(RewriteRule),它将请求传递给平衡代理。该行实际上与两个代理指令行执行的操作大致相同。

如果测试成功(即静态文件存在),它将跳过此行。如果您删除了上面的两行,apache 将从文档根目录提供该文件。然而,有了上面的行,无论如何它最终都会将其传递给代理。然后,正如您所指出的,默认情况下,rails 不会配置为提供此文件,并且会返回 404。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

在Rails中,我应该启用serve_static_assets吗? 的相关文章

随机推荐