Hosting Fonts on Heroku with Cloudfront

913 views
Skip to first unread message

Brandon Hilkert

unread,
Mar 7, 2014, 8:22:11 AM3/7/14
to phusion-...@googlegroups.com
I have a Rails 4 app that I'm hosting on Heroku. I'm using the passenger so all my assets are getting cache-control headers. However. I'm using Cloudfront as an asset CDN, so when fonts are downloaded from an external URL for Firefox, i get an error b/c there's not Access-Control-Allow-Origin headers. I added the following to my config/application.rb:

    config.action_dispatch.default_headers = {
      'X-Frame-Options' => '',
      'Access-Control-Allow-Origin' => '*',
      'Access-Control-Request-Method' => '*'
    }


However, b/c the assets are being served by the downloaded version of Nginx, those headers are integrated and the asset requests never make it to the Rails app.

Is there a way to configure headers for nginx in the Passenger gem?

Brandon Hilkert

unread,
Mar 11, 2014, 3:38:10 PM3/11/14
to phusion-...@googlegroups.com
Any thoughts on this?

gagan...@desiringgod.org

unread,
Mar 11, 2014, 4:09:06 PM3/11/14
to phusion-...@googlegroups.com
Brandon, 

I am facing the same problem. 

It seems though that there is no way to disable nginx from serving static assets. https://groups.google.com/forum/#!searchin/phusion-passenger/static$20files$20/phusion-passenger/C_niqzWeFHM/BMiOlzTNyeMJ

That's quite a bummer. 

Hongli Lai

unread,
Mar 17, 2014, 12:25:37 PM3/17/14
to phusion-passenger
You can solve this by preventing Heroku from precompiling your
assets[1], and then serving assets from the Rails app[2]. This way
your assets will not be served through Nginx.

[1] Create a file public/assets/manifest.yml to prevent Heroku from
precompiling your assets. See
https://devcenter.heroku.com/articles/rails-asset-pipeline#compiling-assets-locally
[2] Enable config.serve_static_assets. See
https://devcenter.heroku.com/articles/rails-4-asset-pipeline#serve-assets
> --
> You received this message because you are subscribed to the Google Groups
> "Phusion Passenger Discussions" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to phusion-passen...@googlegroups.com.
> To post to this group, send email to phusion-...@googlegroups.com.
> Visit this group at http://groups.google.com/group/phusion-passenger.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/phusion-passenger/0e9c7a6b-bbae-4908-bb9a-0e2265d03c60%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
Phusion | Web Application deployment, scaling, and monitoring solutions

Web: http://www.phusion.nl/
E-mail: in...@phusion.nl
Chamber of commerce no: 08173483 (The Netherlands)

Brandon Hilkert

unread,
Mar 17, 2014, 12:29:08 PM3/17/14
to phusion-...@googlegroups.com
To me, hosting assets from Nginx was one of the benefits of using Passsenger on Heroku. If I wanted to serve assets from the application, I could just use unicorn (which is what I ended up doing).


------------------------------------

http://brandonhilkert.com



--
You received this message because you are subscribed to a topic in the Google Groups "Phusion Passenger Discussions" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/phusion-passenger/nskVxnxFssA/unsubscribe.
To unsubscribe from this group and all its topics, send an email to phusion-passen...@googlegroups.com.

To post to this group, send email to phusion-...@googlegroups.com.
Visit this group at http://groups.google.com/group/phusion-passenger.

Hongli Lai

unread,
Mar 17, 2014, 12:34:47 PM3/17/14
to phusion-passenger
In the near future, a method will be provided to customize the Nginx
config file directly in order to set headers for static assets. For
now, this is the way to go.
> https://groups.google.com/d/msgid/phusion-passenger/CAC%3DfdQhYYUjceRZTeJp6d6bQ5ou0HUbfkx%3DTLtydsNMyon-5ZA%40mail.gmail.com.

Brandon Hilkert

unread,
Mar 17, 2014, 12:46:15 PM3/17/14
to phusion-...@googlegroups.com

Hongli Lai

unread,
Mar 17, 2014, 1:04:34 PM3/17/14
to phusion-passenger
And done: https://github.com/phusion/passenger/commit/a23671b677ca340209328951edb607fe348f3b1c

This feature will be included in version 4.0.39.

Brandon Hilkert

unread,
Mar 17, 2014, 1:08:49 PM3/17/14
to phusion-...@googlegroups.com

gagan...@desiringgod.org

unread,
Mar 18, 2014, 12:01:16 PM3/18/14
to phusion-...@googlegroups.com
This is great! Thanks for your work Hongli Lai. 

Gagan 

Augustin Riedinger

unread,
Mar 19, 2014, 1:22:44 PM3/19/14
to phusion-...@googlegroups.com
Thanks for these useful information Hongli Lai.
Is there a way we could test using the version 4.0.39 and have a config file example?

Chen Tom

unread,
Sep 16, 2014, 8:47:23 PM9/16/14
to phusion-...@googlegroups.com
WOW this is great!! Thanks for your work!! AWESOME!!

Hongli Lai於 2014年3月18日星期二UTC+8上午1時04分34秒寫道:
Reply all
Reply to author
Forward
0 new messages