How do I put specific files in the root directory of the Grails server?

I am using grails app as backend for Flex frontend. To be able to easily develop and debug my applications, I will need to put the crossdomain.xml file in the server root, i.e. It should be accessible via http: // localhost: 8080 / crossdomain.xml . Similar use cases could be to deploy favicon.ico or robots.txt, however this can be done in production via tomcat server with default web root application.

In my case, however, I need to have the crossdomain.xml available after running the grails run-app. I know that I can move the whole application to the root directory ( http://ca.rroll.net/2009/03/27/configuring-the-grails-root-application-context/ ) but that is also not what i want since the grails app should still be below the default app context.

Does anyone know how I can do this? Do I have to somehow reconfigure the jetty servlet container of my Grails installation?

0


a source to share


2 answers


I think I found the answer. I haven't tried this yet, so YMMV.

This Colin Harrington article discusses how to create a crossdomain.xml file available in the server root by deploying an additional Jetty context.



His technique was first suggested in this entry blog , where the author also discusses using the Static Resources Plugin as another alternative

+1


a source


I figured out a way to solve this problem using Apache and mod_proxy. This keeps both your Grails installations and Grails project intact. Don't hack into the internals of Grails, don't add plugins you might not need.

1. Install Apache httpd 2.2

Do this, however, in the most convenient way for your operating system. It is important to install Apache 2.2. I did this on an Ubuntu system, so any specific commands and file locations will be generated for Ubuntu. Change your system if necessary.

Once you've installed Apache, run httpd.

sudo /sbin/service httpd start

      

Verify it is installed correctly using your web browser.

2. Create a root directory

Choose a location on the disk where you will save your static files. This will be the document root for httpd. I will be using / var / grails _root.

mkdir /var/grails_root
touch /var/grails_root/crossdomain.xml

      

3. Create VirtualHost in httpd.conf

Open httpd.conf with your favorite text editor.

vim /etc/httpd/conf/httpd.conf

      

Choose your favorite port and create a virtual host on that port. I'll be using 9090, but any port will do.

Add these lines to httpd.conf

Listen 9090
<VirtualHost *:9090>
    DocumentRoot "/var/grails_root"
    <Directory "/var/grails_root">
        Allow from all
    </Directory>
</VirtualHost>

      



Restart httpd

sudo /sbin/service httpd restart

      

Check that you can now access the static files in the root of your document. If not, you will need to fix this before moving on to the next step.

4. Enable mod_proxy and mod_proxy_http

You need to download both of these modules. mod_proxy has the basic functionality for proxying, and mod_proxy_xxx modules have protocol specific information. They ship standard since httpd 2.2, so you don't need to install anything extra.

Add these lines to httpd.conf

LoadModule proxy_module modules/mod_proxy.so
LoadModule proxy_http_module modules/mod_proxy_http.so

      

Now change the virtual host that you created in the previous step. (You can omit comments)

<VirtualHost *:9090>
    DocumentRoot "/var/grails_root"
    <Directory "/var/grails_root">
        Allow from all
    </Directory>
# New lines start here
    ProxyRequests Off
    <Proxy *>
        Order deny,allow
        Allow from all
    </Proxy>
    ProxyPass /grailsApp http://your.grails.server:8080/grailsApp
# New lines end here
</VirtualHost>

      

Restart httpd

sudo /sbin/service httpd restart

      

You can now access your static files and your Grails application on port 9090.

This is all based on information found here: http://docs.codehaus.org/display/JETTY/Configuring+mod_proxy

Information for this with other versions of Apache is available on the same site.

0


a source







All Articles