How can I remove the application name from a Grail

2020-07-08 06:09发布

问题:

I have an application running at a URL like this:

http://myapp.mydomain.com/myapp

I don’t want the /myapp part in the URL. So how can I get rid of the application name? I want just

http://myapp.mydomain.com

to be the URL. How can I do this?

回答1:

bit detailed approach

First Method:

first shutdown your tomcat [from the bin directory (sh shutdown.sh)] then you must delete all the content of your tomcat webapps folder (rm -fr *) then rename your WAR file to ROOT.war finally start your tomcat [from the bin directory (sh startup.sh)]

Second Method:

leave your war file in CATALINA_BASE/webapps, under its original name - turn off autoDeploy and deployOnStartup in your Host element in the server.xml file. explicitly define all application Contexts in server.xml, specifying both path and docBase. You must do this, because you have disabled all the Tomcat auto-deploy mechanisms, and Tomcat will not deploy your applications anymore unless it finds their Context in the server.xml.

Note:

that this last method also implies that in order to make any change to any application, you will have to stop and restart Tomcat.

Third Method:

Place your war file outside of CATALINA_BASE/webapps (it must be outside to prevent double deployment). - Place a context file named ROOT.xml in
CATALINA_BASE/conf//. The single element in this context file MUST have a docBase attribute pointing to the location of your war file. The path element should not be set - it is derived from the name of the .xml file, in this case ROOT.xml. See the Context Container above for details.



回答2:

1) Your app server needs to be configured to have your grails application as ROOT application

2) your grails application context path should be "/" or app.context=/



回答3:

You can make Tomcat serve a webapp as the root context by simply naming it ROOT.war, i.e. take the myapp-0.1.war generated by Grails and copy it to TOMCAT_DIR/webapps/ROOT.war.

If you have a setting for grails.serverURL in your Config.groovy you will need to override this for your production environment to ensure that any absolute links generated by Grails are correct

environments {
  production {
    grails.serverURL = 'http://myapp.mydomain.com'
  }
}

But in Grails 2 it is usually safe to omit grails.serverURL entirely and let the app deduce the right value at runtime. You only need it if you're running behind a reverse proxy that doesn't pass through the correct Host header.