Asset Precompilation OK, but 404 when trying to get files

风流意气都作罢 提交于 2019-12-05 02:12:25

Check your config/environments/production.rb file and add next line to it (if it does not have it yet):

config.serve_static_assets = true

Rails recommends that this setting config.serve_static_assets by default should be disabled i.e. set to false. Here is the default configuration in config/environments/production.rb generated in rails app

Disable Rails's static asset server (Apache or nginx will already do this)

config.serve_static_assets = false

So if you are setting it to true in your local app then that's still fine. But if you are deploying your app on Apache or ngix or anything other than heroku then its not advisable to make config.serve_static_assets=true in your production.rb config file. Here is the documentation in Rails guides.

config.serve_static_files configures Rails itself to serve static files. Defaults to true, but in the production environment is turned off as the server software (e.g. NGINX or Apache) used to run the application should serve static assets instead. Unlike the default setting set this to true when running (absolutely not recommended!) or testing your app in production mode using WEBrick. Otherwise you won't be able use page caching and requests for files that exist regularly under the public directory will anyway hit your Rails app.

URL - http://guides.rubyonrails.org/configuring.html

Can you put this line in your current environment.rb?

config.serve_static_assets=true

Reference: here

Rails 5:

Change config.public_file_server.enabled in production.rb to true or add RAILS_SERVE_STATIC_FILES with any value to env variables.

Reference: https://github.com/rails/rails/pull/18100

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!