Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rails3.1 rc5 and images problem - 200 OK but they don't show (css and js works fine) #2299

Closed
zlw opened this issue Jul 27, 2011 · 46 comments
Closed
Assignees
Milestone

Comments

@zlw
Copy link

zlw commented Jul 27, 2011

I've got problem with images after upgrade (from rc4 to rc5). They just don't show in the browser. There's no 404 when I go to the url /asset/image_name.jpg, not 404 in logs.

log fragment: http://pastie.org/2279109

@dougal
Copy link
Contributor

dougal commented Jul 27, 2011

I'm also seeing this issue. 200 or 304 on the images in question.

Rails 3.1 rc5, REE1.8.7, Passenger 3.0.7.

@zlw
Copy link
Author

zlw commented Jul 27, 2011

I think the problem is with sprockets 2 beta 12. I'm getting the same issue with rails3.1rc4 and sprockets2 beta12 but using sprockets2 beta10 it works fine.

I tried do use rails3.1rc5 with sprockets2 beta 10 but there'r dependency issues.

@dougal
Copy link
Contributor

dougal commented Jul 27, 2011

Tried fetching an asset using curl, content-length is reported as zero.

https://gist.github.com/6b746721a019b275d09a

@spastorino
Copy link
Contributor

Is this not related to #1822 ?
Also can you explain the proper steps to reproduce it? which environment? are you running rake assets:precompile or not? do you have something on the cache? what are the values of config.serve_static_assets and config.action_dispatch.x_sendfile_header ?

@zlw
Copy link
Author

zlw commented Jul 27, 2011

It's similar issue but as I said I've got problem with sprockets2 beta12. #1822 got problem with beta10 (it's working fine with beta10 for me).

  • Environment - production
  • I'm running assets:precompile (but problems exists even without it)
  • Cleared cache
  • served_static_assets = false
  • x_sendfile_header = "X-Sendfile"

Again - after downgrade to rc4 and force sprockets beta10 it's working fine.

@spastorino
Copy link
Contributor

@zlw which http server are you using?

@zlw
Copy link
Author

zlw commented Jul 27, 2011

unicorn + apache2

@spastorino
Copy link
Contributor

@zlw can you check setting x_sendfile_header to nil ?

@pksunkara
Copy link
Contributor

Having the same issue. Just upgraded to rc5 from rc4 and sprockets from beta.10 to beta.12

Edit: By the way, x_sendfile_header = nil doesn't solve the issue

@ncri
Copy link

ncri commented Jul 29, 2011

Not sure if tit's the same issu: Just upgraded to RC5 and now in production the checksums generated by the asset_path is wrong, so the precompiled files are not found. Will try downgrading sprockets to beta10 as suggested.

@ncri
Copy link

ncri commented Jul 29, 2011

Can't downgrade as rails rc5 depends on sprockets beta12

@ncri
Copy link

ncri commented Jul 29, 2011

Rolled back to rc4 until this issue is solved...

@dmathieu
Copy link
Contributor

I do not see this issue in production with rails from the git branch 3-1-stable hosted on heroku and running unicorn.

@zlw
Copy link
Author

zlw commented Jul 29, 2011

@dmathieu On which sprockets version depends 3-1-stable branch? I still think that it's sprockets issue.

@dmathieu
Copy link
Contributor

@ghost ghost assigned spastorino Jul 29, 2011
@koichirose
Copy link

same issue here: 3.1.0rc5, apache with passenger.
CSS and JS are fine.

@koichirose
Copy link

didn't solve it with 3.1.0rc4 and sprockets 2.0.0.beta.10 either :/

@zlw
Copy link
Author

zlw commented Jul 31, 2011

are you sure that you forced 2beta10?

gem "sprockets", "2.0.0.beta.10"

try to remove all versions of sprockets from your system.

@koichirose
Copy link

Yes:

    $ bundle show rails
    /home/koichirose/.rvm/gems/ruby-1.9.2-p290/gems/rails-3.1.0.rc4
    $ bundle show sprockets
    /home/koichirose/.rvm/gems/ruby-1.9.2-p290/gems/sprockets-2.0.0.beta.10

I completely removed 2.0.0.beta.12, too.

@igas
Copy link
Contributor

igas commented Aug 1, 2011

I have same problem on my env(MRI1.9.2, Rails3.1.0.rc5, Sprockets2.0.0.beta.12 and WEBrick/Thin/Unicorn) with -e production: affected image_tag("logo.png") tags - images doesn't displays, but at the same time all backgrounds described in application.css.sass works fine. Also on -e development environment all works fine.

Some logs from -e production

Server logs:

Started GET "/" for 127.0.0.1 at 2011-08-01 15:00:51 +0400
  Processing by HomeController#index as HTML
Rendered home/index.html.haml within layouts/application (68.6ms)
Completed 200 OK in 164ms (Views: 147.8ms | ActiveRecord: 0.5ms)
cache: [GET /assets/logo-ae8cd48a01131edfe93d47bdccd36fd7.png] fresh

HTML output:

<img alt="Logo" src="/assets/logo-ae8cd48a01131edfe93d47bdccd36fd7.png" />

curl -I http://localhost:3000/assets/logo-ae8cd48a01131edfe93d47bdccd36fd7.png output have Content-Length: 0:

2011-08-01 14:41:24 igasgeek ttys002
HTTP/1.1 200 OK
Content-Type: image/png
Content-Length: 0
Cache-Control: public, max-age=31536000
Last-Modified: Sat, 30 Jul 2011 18:50:59 GMT
Etag: "ae8cd48a01131edfe93d47bdccd36fd7"
X-Ua-Compatible: IE=Edge,chrome=1
X-Sendfile: /Volumes/HDD/Code/dadaday/app/assets/images/logo.png
X-Runtime: 0.002316
Date: Mon, 01 Aug 2011 10:04:31 GMT
X-Content-Digest: da39a3ee5e6b4b0d3255bfef95601890afd80709
Age: 3501
X-Rack-Cache: fresh
Server: WEBrick/1.3.1 (Ruby/1.9.2/2011-07-09)
Connection: Keep-Alive

@doabit
Copy link
Contributor

doabit commented Aug 2, 2011

I have same issue

gem 'rails', :git => "git://github.com/rails/rails.git", :branch => "3-1-stable"

gem 'sqlite3'

# Asset template engines      
gem 'sprockets', :git => 'git://github.com/sstephenson/sprockets.git'
gem 'sass-rails', :git => 'git://github.com/rails/sass-rails.git', :branch => '3-1-stable'  

@barthezslavik
Copy link

I have same issue without sprockets :(

@markmcb
Copy link

markmcb commented Aug 2, 2011

Same issue. 3.1.0rc5, apache with passenger. CSS and JS work fine.

@abhid
Copy link

abhid commented Aug 2, 2011

Same issue when using 3.1.0rc5, Thin and nginx. CSS and JS work, images do not.

@koichirose
Copy link

markmcb, abhid, did you manage to make it work with sprockets 2.0beta10 and rails 3.1rc4?

@markmcb
Copy link

markmcb commented Aug 3, 2011

@koichirose, I got it working now. I added 2.0.0.beta.10 to my Gemfile, did a bundle update, restarted the app. That didn't immediately solve the problem. However, running rake assets:precompile after all that seemed to do the trick.

@krzkrzkrz
Copy link

Getting the same problem on Heroku production. CSS and JS files are working fine. But images are not seen. On local dev, everything works fine. Running on Thin.

@krzkrzkrz
Copy link

The problem seems to go away if you change, in production.rb:

config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect'

from

config.action_dispatch.x_sendfile_header = "X-Sendfile"

This works in Heroku at least, since they are using nginx. I can now see asset images accordingly.

@zlw
Copy link
Author

zlw commented Aug 4, 2011

But X-Accel-Redirect is for nginx (relying on documentation). What about apache?

@krzkrzkrz
Copy link

Perhaps RC6 will come up with a fix for Apache

@mrjoshuak
Copy link

Still broken, and now I can't even revert to rc4, and sprockets-2.0.0.beta.10.

"Could not find sprockets-2.0.0.beta.10 in any of the sources"

@koichirose
Copy link

I managed to solve it, with rc4 and beta10, after running the rake task.
Very strangely, though, only some images are fixed. Others show the same exact issue (i.e. they don't show at all).

@bmarini
Copy link
Contributor

bmarini commented Aug 8, 2011

Some of these problems are due to people not understanding how their assets
are getting served now. I hope this explanation helps.

1. Asset is in public folder public/assets/image.png

In this case your http server (apache, nginx) should be serving the image
directly without making a request to your Rails app.

2. Assets are in app/assets but you ran rake assets:precompile

That will precompile your assets into fingerprinted files in public/assets.
Again, your http server should be serving these files. You'll need to use the
Rails helper methods (image_tag, stylesheet_link_tag,
javascript_include_tag) to refer them as their filenames are auto generated,
for example, app/assets/images/rails.png is precompiled to
public/assets/rails-98b2ad0cb353bb02397493893ee07d91.png

3. Rails serves the assets directly

If the Rails configuration serve_static_assets is set to true, rails
will serve the assets. This is tolerable for development but too slow for
production. You don't want Rails serving your image files when you have apache
or nginx in front that can serve them much faster.

4. Rails + X-Sendfile (serve_static_assets = false)

The better way to serve assets that aren't in your public folder is to use
X-Sendfile. Rails will use this option when your config looks like this (this
is the default for production as of rc5):

config.serve_static_assets = false
config.action_dispatch.x_sendfile_header = "X-Sendfile" # Use 'X-Accel-Redirect' for nginx

This means Rails responds to an asset request with an X-Sendfile header. This
header will tell your http server the location of the file to serve, and if
your http server supports X-Sendfile, it'll serve the file instead of an empty
Rails response. An example X-Sendfile header:

X-Sendfile: /Users/ben/Development/railsapp/app/assets/images/rails.png

If you are getting an empty 200 OK response for your images in production, it
is most likely because Rails is serving back the X-Sendfile header and your
http server isn't handling that header. With nginx you need to change the the
header to X-Accel-Redirect.

One gotcha I experienced was I figured app/assets/images/rails.png would be
accessible at http://localhost:3000/assets/images/rails.png but is actually
http://localhost:3000/assets/rails.png

@spastorino
Copy link
Contributor

Things are working for me with current 3-1-stable and sprockets master, possibly after I made config.action_dispatch.x_sendfile_header default to nil.
I've made a new app with a post scaffold and added two lines on application.html.erb in order to show the result of asset_path and image_tag.
Take a look at the app https://github.com/spastorino/asset_pipelining_test and test it on heroku http://empty-stream-704.herokuapp.com/posts.

I'm going to close this issue until someone is able to provide a steps which shows new issues :).

@spastorino
Copy link
Contributor

Things are working for me with current 3-1-stable and sprockets master, possibly after I made config.action_dispatch.x_sendfile_header default to nil.
I've made a new app with a post scaffold and added two lines on application.html.erb in order to show the result of asset_path and image_tag.
Take a look at the app https://github.com/spastorino/asset_pipelining_test and test it on heroku http://empty-stream-704.herokuapp.com/posts.

I'm going to close this issue until someone is able to provide a steps which shows new issues :).

@koichirose
Copy link

I still can't solve this.
I upgraded to Rails 3.1.0 and can't see any of my images in production.
CSS and JS are ok.
I'm using config.assets.compile = true

Here's the repository: https://github.com/koichirose/tvshows
And here's a live installation: http://dev.nerdfeed.it/

All the images return 304 not modified:
Started GET "/assets/banners/46_original.jpg" for 95.36.216.100 at 2011-09-11 19:28:43 +0400
Served asset /banners/46_original.jpg - 304 Not Modified (1ms)

@spastorino
Copy link
Contributor

@ koichirose You have to update your config/application.rb and config/environments/* files.

@koichirose
Copy link

@spastorino: how? I just tried (see commit at https://github.com/koichirose/tvshows ): I copied them from a newly created Rails 3.1 app. Didn't solve it.
I can't even troubleshoot this, since everything's ok according to the logs :/

@guilleiguaran
Copy link
Member

@koichirose can you reset your browser cache and delete all the files in tmp/cache?

@koichirose
Copy link

yeah, it was tmp/cache.
solved now, thank you

@kinopyo
Copy link
Contributor

kinopyo commented Sep 24, 2011

@guilleiguaran remove tmp/cache and worked, thank you so much!
My application was created at 3.1.rc1 and upgrade to rc4-rc5-stable. I think maybe some weird stuff was generated at some point into the tmp/cache, and it won't display the image unless you manually remove the cache.

@zlw
Copy link
Author

zlw commented Sep 27, 2011

I'm still having problem with this. I updated to Rails 3.1 stable (from Rails 3.1 rc4), removed tmp/cache and public/assets, tryin x_sendfile_header.

@jakobsack
Copy link

@zlw did you install the xsendfile module for apache? (Debian: libapache2-mod-xsendfile) Did you activate it for your rails project?

@zlw
Copy link
Author

zlw commented Sep 28, 2011

@jakobsack nope, i'll try that. What do you mean 'activate it for rails project'?

@jakobsack
Copy link

@zlw xsendfile is off by default, you have to enable it. For example set

XSendFile on
XSendFileAllowAbove on

in the apache config for your rails app. See the module documentation for more details.
See the module information

@zlw
Copy link
Author

zlw commented Sep 28, 2011

Ok, that was problem with apache configuration.

For xsendfile mod > 0.10 we need to add:
XSendFilePath /home/username/dir-with-our-app/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests