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

Making it work with Phusion Passenger #23

Open
augnustin opened this issue Mar 18, 2014 · 4 comments
Open

Making it work with Phusion Passenger #23

augnustin opened this issue Mar 18, 2014 · 4 comments

Comments

@augnustin
Copy link

I recently moved to Phusion Passenger. I read (here) that it runs a nginx in front not to query main app.

My guess is that it's what breaks it again. Is there something I can do against this?

This gem is awesome, I struggled trying many solutions and this was my final solution to achieve having cdn fonts in my app. Thanks for support!

@ericallam
Copy link
Owner

Hmmm, I'm not sure why moving to Phusion Passenger on heroku would affect how this app works. The font assets should still be initially served by the Rails app (giving this gem the opportunity to set it's headers). Just make sure you aren't precompiling the assets and you should be fine.

@augnustin
Copy link
Author

Just make sure you aren't precompiling the assets and you should be fine.

Well, I am precompiling assets, on the heroku side. But I used to do that also earlier and the gem still helped me.

Here are the different curls results I get:

curl -H "Origin: http://myapp.com" -X OPTIONS -I http://myapp.com         
HTTP/1.0 200 OK
Access-Control-Allow-Headers: x-requested-with
Access-Control-Allow-Methods: GET
Access-Control-Allow-Origin: http://*.myapp.com
Access-Control-Max-Age: 3628800
Date: Wed, 19 Mar 2014 15:51:47 GMT
Server: nginx/1.4.7 + Phusion Passenger 4.0.40
Status: 200 OK
X-Powered-By: Phusion Passenger 4.0.40
X-Rack-Cache: invalidate, pass
Content-Length: 0
X-Cache: MISS from localhost
X-Cache-Lookup: MISS from localhost:3128
Via: 1.1 localhost:3128 (squid/2.7.STABLE9)
Connection: close

$ curl -H "Origin: http://myapp.com" -I http://myapp.com 
HTTP/1.0 200 OK
Cache-Control: max-age=0, private, must-revalidate
Content-Type: text/html; charset=utf-8
Date: Wed, 19 Mar 2014 15:52:32 GMT
ETag: "00b53fcaa46cad4da90931ac6eb497a9"
Server: nginx/1.4.7 + Phusion Passenger 4.0.40
Set-Cookie: _copass_session=BAh7B0kiD3Nlc3Npb25faWQGOgZFVEkiJWI1MjIwNjlkNWNhNjlmOTIyZjNhZGU5ZDk1NjNmMTk2BjsAVEkiEF9jc3JmX3Rva2VuBjsARkkiMVFSQk5QTjdKU3ZVbjdxQnpaRFd3Y3VJa2wvNWxETE1WWW9Dam5yV1BiNTg9BjsARg%3D%3D--77a76ec73e57238d61c079530e1ac0ca1c0c400a; path=/; HttpOnly
Status: 200 OK
X-Powered-By: Phusion Passenger 4.0.40
X-Rack-Cache: miss
X-Request-Id: 0fef6d7e-e764-410d-9f36-b87bd83a023b
X-Runtime: 0.060597
X-Ua-Compatible: IE=Edge,chrome=1
X-Cache: MISS from localhost
X-Cache-Lookup: MISS from localhost:3128
Via: 1.1 localhost:3128 (squid/2.7.STABLE9)
Connection: close

$ curl -H "Origin: http://myapp.com" -I http://cdn3.myapp.com/assets/libs/libs-0047d596aa9bc6b792f00dc4552a1acb.js
HTTP/1.0 200 OK
Content-Type: application/x-javascript
Content-Length: 533565
Accept-Ranges: bytes
Cache-Control: max-age=315360000
Cache-Control: public
Date: Wed, 19 Mar 2014 15:54:29 GMT
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Last-Modified: Wed, 19 Mar 2014 14:54:04 GMT
Server: nginx/1.4.7
Age: 6
X-Cache: Hit from cloudfront
X-Amz-Cf-Id: 7vycV3bjMkTYvB4kbrn6Rlkq_QDhzov0dYeBLJsk4mMecUMP7MoZ3Q==
X-Cache: MISS from localhost
X-Cache-Lookup: MISS from localhost:3128
Via: 1.1 6f90d6e1ef9cf9ead2a83e7348c2c019.cloudfront.net (CloudFront), 1.1 localhost:3128 (squid/2.7.STABLE9)
Connection: close

$ curl -H "Origin: http://myapp.com" -I http://cdn.myapp.com/assets/bootstrap/glyphicons-halflings-regular-0391150c52d1f65893d1d6b0d29fd0c9.woff
HTTP/1.0 200 OK
Content-Type: font/x-woff
Content-Length: 23292
Accept-Ranges: bytes
Cache-Control: max-age=315360000
Cache-Control: public
Date: Wed, 19 Mar 2014 15:04:18 GMT
Expires: Thu, 31 Dec 2037 23:55:55 GMT
Last-Modified: Wed, 19 Mar 2014 14:54:04 GMT
Server: nginx/1.4.7
Age: 4402
X-Cache: Hit from cloudfront
X-Amz-Cf-Id: BnioUt1UmtgzSgLGb2rbLeYQq9IgTyMUYK4bUZ7X0fO3J93ghmXI5A==
X-Cache: MISS from localhost
X-Cache-Lookup: MISS from localhost:3128
Via: 1.1 e02a2ca059cf50bbf3b3f605d07c75a1.cloudfront.net (CloudFront), 1.1 localhost:3128 (squid/2.7.STABLE9)
Connection: close


And here's my config:

  config.action_controller.asset_host = 'cdn%d.myapp.com'
  config.font_assets.origin = "http://*.myapp.com"

Maybe there's something I missed here ?

@ericallam
Copy link
Owner

If you are precompiling assets then nginx is probably serving the assets from the filesystem and skipping Rails altogether (hence skipping this gem). Which is fine, it just means you need to set the Access Control headers using nginx. I'm not sure if that's possible with the nginx on heroku (I've never used this particular setup myself), but you should be able to google around for "nginx access control headers" and find your way.

@augnustin
Copy link
Author

Well, the googling around did not give me much success unfortunately. 😒

This google group discussion mentions that the option will be available in a near future : https://groups.google.com/forum/#!topic/phusion-passenger/nskVxnxFssA

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

2 participants