Apache不会为rails app提供静态资产

sou*_*ver 8 apache ruby-on-rails asset-pipeline

我正在尝试配置我的apache服务器以从我的rails应用程序提供静态资产.我已经尝试了建议的配置,但我的资产仍然没有显示,当我试图直接访问它时,我刚刚遇到一个rails错误,没有找到匹配的控制器,但资产的东西应该由apache直接处理我认为.我的apache配置如下所示:

<VirtualHost *:80>
ServerName xxx
DocumentRoot /home/xxx/test/public
PassengerEnabled off

<LocationMatch "^/assets/.*$">
Header unset ETag
FileETag None
ExpiresActive On
ExpiresDefault "access plus 1 year"
</LocationMatch>
ProxyPass / http://127.0.0.1:9292/
ProxyPassReverse / http://127.0.0.1:9292/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

我错过了什么吗?

cly*_*yde 0

我用了,

RAILS_ENV=production bundle exec rake assets:precompile
Run Code Online (Sandbox Code Playgroud)

为了使其一切正常,我将其添加到 config/application.rb...

module MyApp
  class Application < Rails::Application
.
.
    config.assets.precompile += ['custom.css']    
    config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
.
.
  end
end
Run Code Online (Sandbox Code Playgroud)

(我创建了 custom.css.scss。但是 Rails 无法识别 .scss,如您在上面看到的。)我假设预编译后您的所有资源都出现在 public/assets 文件夹中。我不明白你在用 LocationMatch 做什么,请原谅我的无知。此外,我没有使用端口 80。我使用了 8000。不确定这是否有区别。

另外,config/environments/Production.rb 中有一个设置,

# Disable Rails's static asset server (Apache or nginx will already do this).
config.serve_static_assets = false
Run Code Online (Sandbox Code Playgroud)

  • 抱歉,但这不太适合我的问题。我已经完成了您提到的所有步骤,但如果我理解正确,则在提供资产时不应涉及轨道。Apache 应该自己做这件事。因此就是“LocationMatch”。但rails仍在处理对assets目录的请求,这应该由apache直接完成 (2认同)