2012-07-28 44 views
0

我在Heroku上使用Grails堆棧來部署應用程序。我希望能夠以myapp.herokuapp.com/xyz的根而不是myapp.herokuapp.com的方式服務我的應用程序,就像我能夠從localhost:8080/xyz的根目錄服務開發一樣。我試着將Config.groovy中一個grails.app.context像這樣:配置Heroku Grails應用程序的根URL

environments { 
    production { 
      grails.app.context = "/xyz" 
    } 
} 

但它似乎並沒有在部署的效果。我需要用Heroku配置什麼?有任何想法嗎?

回答

1

它看起來就像你有一個jetty-web.xml文件添加到WEB-INF目錄設置上下文路徑:

<?xml version="1.0" encoding="UTF-8"?> 
<!-- File: web-app/WEB-INF/jetty-web.xml --> 
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://jetty.mortbay.org/configure.dtd"> 
<Configure class="org.mortbay.jetty.webapp.WebAppContext"> 
    <Set name="contextPath">/xyz</Set> 
</Configure> 

如果這有助於適當的信貸去this網站,這是從一個文章鏈接上Grails and Heroku Tomas Lin。

+0

不幸的是,這似乎並不像Heroku上寫的那樣工作。我創建了'/ web-app/WEB-INF/jetty-web.xml'並粘貼上面,在產品中獲得了一個404命中'/ xyz'。我想知道如果Heroku在啓動應用程序時看到並使用了'jetty-web.xml'文件。 – 2012-07-29 16:11:09

0

我不認爲你可以設置當前的Grails build pack上下文路徑。如果你覺得這樣,你可以分解構建包並破解它以支持設置上下文(有關構建包的更多信息,請參閱build pack doc)。

另一種選擇是將您的Grails應用程序本地構建到WAR文件中並使用WAR deployment部署WAR文件。 WAR部署過程將使用webapp-runner實用程序在Tomcat上運行您的應用程序,並支持配置上下文路徑。下面是幫助輸出爲webapp的亞軍7.0.22.3(我碰巧已經安裝,可能會稍顯落伍):

Tomcat Runner runs a Java web application that is represented as an exploded war in a Tomcat container Usage: java -jar tomcat-runner.jar [arguments...] path/to/webapp Arguments: --session-timeout The number of minutes of inactivity before a user's session is timed out
--port The port that the server will accept http requests on
--context_xml The parth to the context xml to use
--path context path (default is /)
--session_manager session store to use (valid options are 'memcache')
--session_manager_operation_timeoutoperation timeout for the memcached session manager. (default is 5000ms)
--session_manager_locking_modeSession locking mode for use with memcache session store. (default is all)
--session_manager_ignore_patternRequest pattern to not track sessions for. Valid only with memcache session store. (default is '.*\.(png|gif|jpg|css|js)$'

WAR deploy doc解釋,你可以爲Web應用程序,亞軍選項你的webapp使用WEBAPP_RUNNER_OPTS config var。