Rails 3.2 Asset Pipeline with Thin and Apache, not finding assets

安稳与你 提交于 2019-12-01 03:28:21

I've been having this problem for days now. Thought it was an issue with capistrano or the ruby version however I'm pretty sure it's permissions related too.

My configuration was pretty much the same as yours although I'm also using Unicorn.

Here's what I did to sort:

  1. Temporarily remove the following section because I think that was causing problems with the troubleshooting:

     <LocationMatch "^/assets/.*$">
      Header unset ETag
        FileETag None
        ExpiresActive On
        ExpiresDefault "access plus 1 year"
      </LocationMatch>
    

Perhaps get it all working and then add it back in. I don't think it's the cause of the problems however, when diagnosing things like this, it's best to remove as much as you can to find the culprit.

  1. Run a chown -R xxx.xxx (replace xxx with your application user or web user) on the public directory. As soon as I did so, the css appeared again.

  2. (What I did but maybe not essential) You might also want to install locally without cap. just in case there's an issue with it. That also worked for me.

  3. Completely wipeout tmp/cache and public/* just in case.

  4. Restart your apache server a couple of times.

You can see a gist of my conf. here

Ryan

Delete the following lines from your Apache configuration.

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

The answer came from In Rails, should I enable serve_static_assets?.

Typically, your assets should only exist in /public/assets for a deployed application.

Apache should be configured so that its DocumentRoot is your RAILS_ROOT/public. Then it will serve http://example.com/assets/whatever.css from RAILS_ROOT/public/assets/whatever.css, and it never goes through Rails for static assets.

Have you restarted your application since you precompiled your assets? Sometimes Rails is expecting an older/newer compiled version of your assets than is currently deployed.

Try removing the ProxyPass and ProxyPassReverse directives from your apache/thin configuration. The P flag in your rewrite rule is already performing the proxy pass that you desire.

See http://httpd.apache.org/docs/2.0/mod/mod_proxy.html for more information.

Passanger knows its a RoR application as there is a config.ru file.

The same error you are reporting happened to me due to wrong permissions. Apache was not able to serve the files inside assets, but was able to send the files on public/

In my case I use capistrano so assets was a symlink to shared/public/assets.

what I did was:

chmod -R o+x shared/ 

x permissions are required to list and access directories. After that it worked. You have to make sure that assets has +x for others

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