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

发布于 12-11 09:17 字数 1207 浏览 1 评论 0原文

我目前正在使用 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>

I am currently using Apache to proxy to Thin (using this article)

None of my static assets work (e.g. stylesheets, javascripts). Is Apache supposed to be serving them or do I have to enable config.serve_static_assets in config/environments/production.rb? If Apache is supposed to serve them, then what am I probably doing wrong?

Here is my Apache config:

<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>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

入画浅相思2024-12-18 09:17:18

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

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

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

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

Delete the following two proxy directive lines and it should work:

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

The first rewrite line (RewriteCond) is a test to see if the file exists on the filesystem in the public directory. If it fails, it continues to the next rewrite line (RewriteRule), which passes the request to the balanced proxy. This line actually does much the same thing as the two proxy directive lines.

If the test succeeds (i.e the static file exists), it'll skip this line. If you've removed the two lines above, apache would then serve the file from the document root. However, with the lines above in, it'll just end up passing it over to the proxy anyway. Then as you pointed out, rails won't be configured to serve this file by default and will return a 404.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文