1

I generally run Grails 2.0 from my IDE but have been seeking to deploy an app to a remote Virtual Private Server (linux) where I installed Tomcat and Mysql. I create a production WAR file and copy it to the Tomcat webapps dir, where I can see Tomcat restart and after some "fixing" I see the application come up, adding minimal bootstrap entries into the MySql database fine.

However, I cannot connect to the Grails app (remotely). If I specify www.mydomain.com, I am (finally) able to reach the main Tomcat server "welcome page". I also reach Tomcat if I add a "/" at the end, not my grails app.

As such I'm tried putting in full controller paths that I know work on my dev machine, and then accessing them on the remote machine (note grails.serverURL is configured as http://www.mydomain.com). Doing this, I get

 HTTP Status 404 -- The requested resource (/BareBones/bare/create) is not available.

This error is from a BareBones application I created, as I was having some problems with VPS available memory. In any case, on my dev machine I can reach the this BareBones app URL

   http://localhost:8080/BareBones/bare/create

as expected. When I deploy, I get the same HTTP Status 404 error (resource not available) when I do:

   http://www.mydomain.com/bare/create

In Config.groovy, in this BareBones app I've got the minimal change:

  environments {
     development {
        grails.logging.jul.usebridge = true
     }
    production {
       grails.logging.jul.usebridge = false

       grails.serverURL = "http://www.mydomain.com"
    }
 }

In my Tomcat server.xml file I changed over from the default 8080/8443 ports to 80/443, but using either either set results in the same problem.

I'm probably missing an easy step, just don't know what it is.


P.S. When I deploy the sample.war file that comes with Tomcat (isn't Grails, just a hello-world servlet), it works. I'm able to access that at

  www.mydomain.com/sample

Since I FTP'd sample.war from my computer to the server, it would appear to indicate my FTPs are good, and the routing to the server is right, narrowing this down to Grails & Tomcat.

Ray
  • 5,885
  • 16
  • 61
  • 97

1 Answers1

2

Usually in dev mode Grails mounts, as you pointed out, the context of appName, i.e. http://localhost:8080/BareBones/ here.

But the path it mounts on tomcat is not up to Grails itself, it is wholly dependent on the Tomcat configuration and primarily the name of the WAR file.

Even if you have BareBones as your appName and you deploy it as ROOT.war then it will mount the root "/" context. If you deploy it as BareBones.war then it should mount the same dir as in dev mode.

Because sites are usually mounted as ROOT.war "/", I can recommend setting

grails.app.context = "/"

in your Config.groovy file which will make it so that you will use the root context path also in dev, i.e. http://localhost:8080/

This makes it simpler since both dev and production will now have identical relative paths to everywhere and only the hostname:port will change.

Jan Wikholm
  • 1,557
  • 1
  • 10
  • 19
  • Jan - Thanks, am trying this now (after not finding app.context in the grails 2.0 manual, which frankly surprises me!). Before I switch over -- will report shortly with result, I changed the default BareBones-0.1.war name Grails gives to BareBones.war. When I then try to url ../BareBones/bare/create, I still get no response. If I understood you correctly this should work? Related, have you found official Grails documentation on app.context? (I want to file a JIRA if this undocumented, which seems like a painful omission if indeed absent). – Ray Feb 08 '12 at 05:48
  • The mount point Tomcat uses usually depends on the filename but there could be additional configurations that would for example cause the first app to always be root regardless of the name, but usually it should work. A quick Google found me only the origin of the feature in Grails: http://jira.grails.org/browse/GRAILS-2534 – Jan Wikholm Feb 08 '12 at 05:54
  • Tried the change, and am not getting a response on www.mydomain.com/bare/create or .../bare/list. In my development env, these come up as http://localhost:8080/bare/create. Do you know what the "right" port settings are in Tomcat's server.xml? Do I need to switch over from the default 8080 port it comes with to 80 for this to work? Accessing http://www.mydomain.com:8080/bare/create doesn't work. – Ray Feb 08 '12 at 05:59
  • Switched server.xml to use port 80, and with the grails.app.context = "/", I still get no response on www.mydomain.com/bare/create. – Ray Feb 08 '12 at 06:10
  • We usually don't have tomcat serving 80, but we have Apache on :80 and then proxying the requests to tomcat to its default port. Does requesting just www.mydomain.com/ return anything? – Jan Wikholm Feb 08 '12 at 06:28
  • Yes, it returns the default Tomcat screen (successfully installed Tomcat), with or without the slash at the end. Also, (please see end of problem for update), when I use the sample.war file provided by Tomcat, I'm able to reach the sample servlet on www.mydomain.com/sample. – Ray Feb 08 '12 at 06:38
  • Amazingly when I got rid of the recommended grails.serverURL setting outlined in Config.grooy, it worked. Saw this S.O. question: http://stackoverflow.com/questions/8933356/how-do-i-set-grails-serverurl-in-an-enterprise-environment-when-i-dont-know-the. I'm going to try now also removing app.context. – Ray Feb 08 '12 at 07:00
  • Wonderful ... am trying to reproduce each case so I can write it up as a JIRA, but everything that worked before is now intermittent or not working. I'm "DONE" with Tomcat. – Ray Feb 08 '12 at 07:42