问题描述
我创建了grails应用程序,并将它上传到了heroku中。
如果我使用了'heroku scale web = 1',那么一切看起来都不错。但是如果我运行'heroku scale web = 2',一些静态资源就会消失。
从日志中我可以看出,来自web.2 dyno的所有静态资源都缺失。但是这个dyno是在没有任何错误的情况下启动的。
我该如何解决这个问题?
这会在启动时告诉应用服务器资源存在前面,avoi例如,正如在我以前的电子邮件中,MyResources.groovy看起来像:
modules = {
application {
resource url:'js / application.js'
resource url:'js / ui.geo_autocomplete.js '
}
}
所以,你可以使用两种方法 - 显式指定资源,或使用adhoc加载(将以下内容添加到您的Config.groovy中:)
pre $ grails.resources.adhoc .includes = []
grails.resources.adhoc.excludes = [*]
它基本上禁用了特别的资源处理。
I have created grails application and uploaded it in heroku.
If I use 'heroku scale web=1' everything looks OK. But if I run 'heroku scale web=2', some static resources disappear.
From logs I can figure out, that all static resources from web.2 dyno are missing. But this dyno is started without any errors.
How can I resolve this problem?
https://github.com/grails-plugins/grails-resources/pull/11
According to the owner of the resources plugin, Marc Palmer, they're ignoring a check for old references to static resources.
So, this manifests itself as a load balancing issue that you would have on any system if you're not using sticky load balancing (which is the case with Heroku). Here's what's happening in the Heroku case:
- Request comes into someapp.com
- index.gsp is served from app server 1, web.1index.gsp contains
- The resources plugin generates a mapping from /static/js/resource.js to /js/resource.js on web.1
- The client makes a request for /static/js/resource.js
- The request is routed to a different app server, web.2
- /static/js/resource.js has not been mapped on web.2 and 404s
From my research, the best practice is to declare your resources in a resources file.
See the following:
http://grails-plugins.github.com/grails-resources/guide/3.%20Declaring%20resources.html
This will tell the app server at boot time that a resource exists up front, avoiding the adhoc loading process.
For example, as in my previous email, a MyResources.groovy would look like:
modules = {
application {
resource url:'js/application.js'
resource url:'js/ui.geo_autocomplete.js'
}
}
So, you can use either of the two methods -- explicitly specify resources, or use adhoc loading (add the following to your Config.groovy: )
grails.resources.adhoc.includes = []
grails.resources.adhoc.excludes = ["*"]
It essentially disables adhoc resource processing.
这篇关于Heroku,Grails:如果使用多个Web dynos,缺少资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!