加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

ruby-on-rails – 在Rails中,我应该启用serve_static_assets吗?

发布时间:2020-12-17 01:27:53 所属栏目:百科 来源:网络整理
导读:我目前正在使用Apache代理瘦(使用此 article) 我的静态资产都不起作用(例如样式表,javascripts). Apache应该为它们提供服务还是我必须在config / environments / production.rb中启用config.serve_static_assets?如果Apache应该为他们服务,那么我可能做错了
我目前正在使用Apache代理瘦(使用此 article)

我的静态资产都不起作用(例如样式表,javascripts). 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>

解决方法

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

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

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

如果测试成功(即静态文件存在),它将跳过此行.如果您已删除上面的两行,则apache将从文档根目录提供该文件.但是,使用上面的行,它最终会最终传递给代理.然后正如您所指出的那样,默认情况下rails不会配置为提供此文件,并将返回404.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读