Quantcast

Grails context big problem with apache mod_proxy

classic Classic list List threaded Threaded
9 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Grails context big problem with apache mod_proxy

Radu Andrei Tanasa
Hi guys,

Here's my deployment scenario:

Apache http server with mod_proxy -> Tomcat 6

In tomcat I have a grails application test.war. Everywhere I used the
createLink methods and g:link tags, so all URL are generated dependent
on the application's context (war name that is).
Now, in apache I have these configurations:

ProxyPass / ajp://localhost:8019/test/
ProxyPassReverse / [***]ajp://localhost:8019/test

The big problem is that the context is doubled. Here's how it goes:

Access http://test.domain.com -> apache proxies to tomcat on /test ->
tomcat gives the html response with all links to scripts,css, etc as
http://test.domain.com/test which triggers the doubling of the context.
When this reaches apache, it addes the /test again so we end up having
http://test.domain.com/test/test/css/main.css which is wrong.

I get this for ALL urls across the application. I really do not know how
to solve this problem. Is there a way to force grails generate all links
with the context / ? Otherwise I will have to change everything manually
and lose the valuable help of grails methods and tags.

Hoping for a positive outcome,
Radu

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails context big problem with apache mod_proxy

Ian Roberts
Radu Andrei Tanasa wrote:
> Is there a way to force grails generate all links
> with the context / ? Otherwise I will have to change everything manually
> and lose the valuable help of grails methods and tags.

Whenever I run a grails application (or any tomcat application) behind
an apache front end I always run it with the tomcat context path the
same as the proxy path, i.e. if I want the final app to be
http://test.domain.com/ then I'd run it at the root context in tomcat
(i.e. name it ROOT.war) and use ProxyPass / ajp://localhost:8019/.
Could this work for you or do you need to run other webapps on the same
tomcat?

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails context big problem with apache mod_proxy

Radu Andrei Tanasa
Hi Ian,

That should work indeed, unfortunately, we'll need multiple apps in the same tomcat. :-(

Radu
Radu Andrei Tanasa wrote:
  
Is there a way to force grails generate all links
with the context / ? Otherwise I will have to change everything manually
and lose the valuable help of grails methods and tags.
    

Whenever I run a grails application (or any tomcat application) behind
an apache front end I always run it with the tomcat context path the
same as the proxy path, i.e. if I want the final app to be
http://test.domain.com/ then I'd run it at the root context in tomcat
(i.e. name it ROOT.war) and use ProxyPass / ajp://localhost:8019/.
Could this work for you or do you need to run other webapps on the same
tomcat?

Ian

  

--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails context big problem with apache mod_proxy

Ian Roberts
Radu Andrei Tanasa wrote:
>  Hi Ian,
>
> That should work indeed, unfortunately, we'll need multiple apps in the
> same tomcat. :-(

I've not tried it myself but I know that Tomcat does support virtual
hosting (i.e. more than one <Host> element in server.xml) so you might
be able to use that, i.e. have your app as the ROOT.war of <Host
name="test.domain.com"> and have your other apps in a different <Host>.

http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html

Ian

--
Ian Roberts               | Department of Computer Science
[hidden email]  | University of Sheffield, UK

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails context big problem with apache mod_proxy

Radu Andrei Tanasa
Thank you. I'll give it a try!

Radu
Radu Andrei Tanasa wrote:
  
 Hi Ian,

That should work indeed, unfortunately, we'll need multiple apps in the
same tomcat. :-(
    

I've not tried it myself but I know that Tomcat does support virtual
hosting (i.e. more than one <Host> element in server.xml) so you might
be able to use that, i.e. have your app as the ROOT.war of <Host
name="test.domain.com"> and have your other apps in a different <Host>.

http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html

Ian

  

--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails context big problem with apache mod_proxy

Mirko Weber-4
I use for this the proxy_html modul, to rewrite also the content of the html-response eg

ProxyHTMLExtended On
ProxyHtmlURLMap / /test

also for Cookies and inside Javascipt. Read in http://apache.webthing.com/mod_proxy_html/

regards,
Mirko

2010/1/7 Radu Andrei Tanasa <[hidden email]>
Thank you. I'll give it a try!

Radu

Radu Andrei Tanasa wrote:
  
 Hi Ian,

That should work indeed, unfortunately, we'll need multiple apps in the
same tomcat. :-(
    
I've not tried it myself but I know that Tomcat does support virtual
hosting (i.e. more than one <Host> element in server.xml) so you might
be able to use that, i.e. have your app as the ROOT.war of <Host
name="test.domain.com"> and have your other apps in a different <Host>.

http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html

Ian

  

--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails context big problem with apache mod_proxy

Radu Andrei Tanasa
Hi Mirko,

Thanks for the suggestion! What do you think about Rewrite rules? Would that work before entering the proxy?
I use for this the proxy_html modul, to rewrite also the content of the html-response eg

ProxyHTMLExtended On
ProxyHtmlURLMap / /test

also for Cookies and inside Javascipt. Read in http://apache.webthing.com/mod_proxy_html/

regards,
Mirko

2010/1/7 Radu Andrei Tanasa <[hidden email]>
Thank you. I'll give it a try!

Radu

Radu Andrei Tanasa wrote:
  
 Hi Ian,

That should work indeed, unfortunately, we'll need multiple apps in the
same tomcat. :-(
    
I've not tried it myself but I know that Tomcat does support virtual
hosting (i.e. more than one <Host> element in server.xml) so you might
be able to use that, i.e. have your app as the ROOT.war of <Host
name="test.domain.com"> and have your other apps in a different <Host>.

http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html

Ian

  

--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email


--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails context big problem with apache mod_proxy

Mirko Weber-4
For me mod_proxy + mod_proxy_balancer + mod_proxy_html works good. I have a configuarion of apache in front of tomcat and for every app a little config-snipplet like this:

<Location /testApp/ >
        ProxyPass balancer://japps/testApp-prod-version/
        ProxyPassReverse /testApp-prod-version
        SetOutputFilter  proxy-html
        ProxyHTMLExtended On
        ProxyHTMLDoctype HTML
        ProxyHtmlURLMap /testApp-prod-version /testApp
</Location>

and so I can change very quick the acitve version(think of version above as 1.2 eg) of a app to the customer in this file and make a apache reload to apply this to customer. And on the real appserver I can deploy more apps and different versions.

Regards,
Mirko

2010/1/7 Radu Andrei Tanasa <[hidden email]>
Hi Mirko,

Thanks for the suggestion! What do you think about Rewrite rules? Would that work before entering the proxy?

I use for this the proxy_html modul, to rewrite also the content of the html-response eg

ProxyHTMLExtended On
ProxyHtmlURLMap / /test

also for Cookies and inside Javascipt. Read in http://apache.webthing.com/mod_proxy_html/

regards,
Mirko

2010/1/7 Radu Andrei Tanasa <[hidden email]>
Thank you. I'll give it a try!

Radu

Radu Andrei Tanasa wrote:
  
 Hi Ian,

That should work indeed, unfortunately, we'll need multiple apps in the
same tomcat. :-(
    
I've not tried it myself but I know that Tomcat does support virtual
hosting (i.e. more than one <Host> element in server.xml) so you might
be able to use that, i.e. have your app as the ROOT.war of <Host
name="test.domain.com"> and have your other apps in a different <Host>.

http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html

Ian

  

--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email


--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Grails context big problem with apache mod_proxy

Adam Evans
I use mod_proxy + mod_proxy_html in a similar setup to below. Pay attention to the ProxyHTMLDoctype and make sure you have the correct value set. proxy_html attempts to clean up the document and you can see some weird things happen if this isn't set to the correct value.

mod_rewrite works for for resources such as images, javascripts etc but will fail on form submissions, this is why I use the proxy_html approach.

If deployed in tomcat under a context path but apache needs to serve it as root i do something like below:


<VirtualHost *:80>
        ServerName example.com
        ServerAlias www.example.com

       ProxyRequests Off
       ProxyPreserveHost On
     
       <Proxy *>
           Order deny,allow
           Allow, from all
       </Proxy>

        RewriteEngine On
        #Force http://example.com to redirect to http://www.example.com ...good seo
        RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
        RewriteRule ^(.*)$ http://www.example.com$1 [L,R=301]

        #Got something not caught by mod_proxy_html? 301 redirect
        # (note doesn't work for forms, only resources)
        RewriteRule "/my-app/(.*)$" "http://www.example.com/$1" [L,R=301]

        ProxyPass ajp://localhost:8009/my-app
        ProxyPassReverse /my-app
        ProxyPassReverseCookiePath /my-app
        SetOutputFilter  INFLATE-proxy-html;DEFLATE
        ProxyHTMLExtended On
        ProxyHTMLDoctype XHTML Legacy
        ProxyHtmlURLMap /my-app
</VirtualHost>

I like using the ui_performance plugin which aggregates + gzips javascript files etc. Grails gzipping these then Apache WS decompressing then recompressing them in apache probably isn't such a good idea but not found a way around this yet.

Mirko Weber-4 wrote
For me mod_proxy + mod_proxy_balancer + mod_proxy_html works good. I have a
configuarion of apache in front of tomcat and for every app a little
config-snipplet like this:

<Location /testApp/ >
        ProxyPass balancer://japps/testApp-prod-version/
        ProxyPassReverse /testApp-prod-version
        SetOutputFilter  proxy-html
        ProxyHTMLExtended On
        ProxyHTMLDoctype HTML
        ProxyHtmlURLMap /testApp-prod-version /testApp
</Location>

and so I can change very quick the acitve version(think of version above as
1.2 eg) of a app to the customer in this file and make a apache reload to
apply this to customer. And on the real appserver I can deploy more apps and
different versions.

Regards,
Mirko

2010/1/7 Radu Andrei Tanasa <radu.tanasa@lightwaysoftware.com>

>  Hi Mirko,
>
> Thanks for the suggestion! What do you think about Rewrite rules? Would
> that work before entering the proxy?
>
> I use for this the proxy_html modul, to rewrite also the content of the
> html-response eg
>
>  ProxyHTMLExtended On
> ProxyHtmlURLMap / /test
>
>  also for Cookies and inside Javascipt. Read in
> http://apache.webthing.com/mod_proxy_html/
>
>  regards,
> Mirko
>
> 2010/1/7 Radu Andrei Tanasa <radu.tanasa@lightwaysoftware.com>
>
>>  Thank you. I'll give it a try!
>>
>> Radu
>>
>>  Radu Andrei Tanasa wrote:
>>
>>
>>   Hi Ian,
>>
>> That should work indeed, unfortunately, we'll need multiple apps in the
>> same tomcat. :-(
>>
>>
>>  I've not tried it myself but I know that Tomcat does support virtual
>> hosting (i.e. more than one <Host> element in server.xml) so you might
>> be able to use that, i.e. have your app as the ROOT.war of <Host
>> name="test.domain.com"> and have your other apps in a different <Host>.
>> http://tomcat.apache.org/tomcat-6.0-doc/virtual-hosting-howto.html
>>
>> Ian
>>
>>
>>
>>
>>  --------------------------------------------------------------------- To
>> unsubscribe from this list, please visit:
>> http://xircles.codehaus.org/manage_email
>
>
>
>  --------------------------------------------------------------------- To
> unsubscribe from this list, please visit:
> http://xircles.codehaus.org/manage_email
>
Loading...