Apache VirtualHost to Glassfish Applications

Alles, was den Apache betrifft, kann hier besprochen werden.

Apache VirtualHost to Glassfish Applications

Postby Traxxas10 » 16. October 2018 10:43

Hello,

I'm running two glassfish applications under
http://serverip:8080/app1
http://serverip:8080/app2

and now I will configure two virtualhosts from the domains:

www.domain1.com -> http://serverip:8080/app1
www.domain2.com -> http://serverip:8080/app2

The configuration:
two .config files under /etc/apache2/sites-available
content:
Code: Select all
<VirtualHost *:80>
        ServerName domain1.com
        ServerAlias www.domain1.com
        ProxyPass /app1  http://127.0.0.1:8080/app1
        ProxyPassReverse /app1 http://127.0.0.1:8080/app1
</VirtualHost>


after the command a2ensite and reload, Google chrome shows me the application with the url www.domain1.com/app1
Firefox and IE show me the default apache site and the url www.domain1.com

my goal:
show me the application with domain www.domain1.com

do you have any idea how i can let it work on each browser without /app1 in the domain?


My system:
ubuntu 16.04 LTS
glassfish 4.1
apache 2
mod_rewrite
mod_proxy


best regards
Traxxas10
 
Posts: 7
Joined: 16. October 2018 10:33
XAMPP version: 1
Operating System: ubuntu 16.04

Re: Apache VirtualHost to Glassfish Applications

Postby Nobbie » 16. October 2018 13:50

First of all, all browsers should show the same content, Apache does not behave different for different browsers. Maybe browsers cache problems.

At next, simply change /app1 to / in you configuration:

Code: Select all
        ProxyPass /  http://127.0.0.1:8080/app1
        ProxyPassReverse / http://127.0.0.1:8080/app1


or simply leave out the first parameter totally:

Code: Select all
        ProxyPass http://127.0.0.1:8080/app1
        ProxyPassReverse http://127.0.0.1:8080/app1
Nobbie
 
Posts: 10541
Joined: 09. March 2008 13:04

Re: Apache VirtualHost to Glassfish Applications

Postby Traxxas10 » 16. October 2018 13:56

Thanks,
yes, it was a cache problem.

after I changed from /app1 to / , the application is shown, but with missing css files.

checking the sourcecode shows me the following link to css: href="/app1/style.css"

i think its now time for rewriterules?
Traxxas10
 
Posts: 7
Joined: 16. October 2018 10:33
XAMPP version: 1
Operating System: ubuntu 16.04

Re: Apache VirtualHost to Glassfish Applications

Postby Nobbie » 16. October 2018 14:05

Traxxas10 wrote:checking the sourcecode shows me the following link to css: href="/app1/style.css"

i think its now time for rewriterules?


No, thats by far more difficult, you cannot solve that by rewriting URLs. See this tutorial for reverse proxys http://www.apachetutor.org/admin/reverseproxies and especially see the chapter "Fixing HTML Links".

I am not sure if

Code: Select all
ProxyHTMLUrlMap /app1/ /


will do the job.
Nobbie
 
Posts: 10541
Joined: 09. March 2008 13:04

Re: Apache VirtualHost to Glassfish Applications

Postby Traxxas10 » 16. October 2018 14:31

After a server crash I could restore everything except the apache virtualhost configuration and now I have no idea how to display it correctly again. But I'm quiet sure, it was without "ProxyHTML[...]" last time (Dec 2017)

this is my actual configuration file:

Code: Select all
<VirtualHost *:80>
        ServerName domain1.com
        ServerAlias www.domain1.com

        ProxyPass / http://127.0.0.1:8080/app1/
        ProxyPassReverse / http://127.0.0.1:8080/app1/
        ProxyHTMLURLMap /app1/ /

</VirtualHost>
Traxxas10
 
Posts: 7
Joined: 16. October 2018 10:33
XAMPP version: 1
Operating System: ubuntu 16.04

Re: Apache VirtualHost to Glassfish Applications

Postby Nobbie » 16. October 2018 14:51

Of course we can try to rewrite the URL, unfortunately the tutorial handles a different case than this. Instead of ProxyHTML.... (remove that line) we insert a simple rewrite:

Code: Select all
<VirtualHost *:80>
        ServerName domain1.com
        ServerAlias www.domain1.com

        RewriteEngine On
        RewriteRule app1/(.*) $1

        ProxyPass / http://127.0.0.1:8080/app1/
        ProxyPassReverse / http://127.0.0.1:8080/app1/

</VirtualHost>


Maybe we have to redirect after rewrite, try to append these flags if necessary:
Code: Select all
        RewriteRule app1/(.*) $1   [R, L]
Nobbie
 
Posts: 10541
Joined: 09. March 2008 13:04

Re: Apache VirtualHost to Glassfish Applications

Postby Traxxas10 » 16. October 2018 15:02

Thanks you, but there are no changes (and no errors) to see.

My configuration:
Code: Select all
<VirtualHost *:80>
        ServerName domain1.com
        ServerAlias www.domain1.com

        ProxyPass / http://127.0.0.1:8080/app1/
        ProxyPassReverse / http://127.0.0.1:8080/app1/

        RewriteEngine On
        RewriteRule app1/(.*) /$1

</VirtualHost>


Link to files:
Code: Select all
 href="/app1/.."



Edit: but I can manually open www.domain1.com/style.css
Traxxas10
 
Posts: 7
Joined: 16. October 2018 10:33
XAMPP version: 1
Operating System: ubuntu 16.04

Re: Apache VirtualHost to Glassfish Applications

Postby Nobbie » 16. October 2018 15:12

Why did you switch the order? I placed the rewrite above the ProxyPass. Your version CANNOT work. Also try to apply the redirect as shown.
Nobbie
 
Posts: 10541
Joined: 09. March 2008 13:04

Re: Apache VirtualHost to Glassfish Applications

Postby Traxxas10 » 16. October 2018 15:17

I changed the order again and there are still no changes.

the other rewriterule failed

Job for apache2.service failed because the control process exited with error code. See "systemctl status apache2.service" and "journalctl -xe" for details.

(RewriteRule: bad flag delimiters)

EDIT:
Ok I fixed it and remove the space before L.
Code: Select all
RewriteRule app1/(.*) $1   [R,L]

but no changes on the site and css files :-(
Traxxas10
 
Posts: 7
Joined: 16. October 2018 10:33
XAMPP version: 1
Operating System: ubuntu 16.04

Re: Apache VirtualHost to Glassfish Applications

Postby Nobbie » 16. October 2018 15:28

I cannot do anymore, i have no glassfish on my laptop and cannot run tests, i am on a cruise currently and have no environment for testing. You should find it out on your own with all these tutorials and documentations.
Nobbie
 
Posts: 10541
Joined: 09. March 2008 13:04

Re: Apache VirtualHost to Glassfish Applications

Postby Traxxas10 » 16. October 2018 15:37

I could fix it a bit more after removing some /

Here my config:

Code: Select all
<VirtualHost *:80>
        ServerName domain1.com
        ServerAlias www.domain1.com


        RewriteEngine On
        RewriteRule app1/(.*) $1   [R,L]

        ProxyPass / http://127.0.0.1:8080/app1/
        ProxyPassReverse / http://127.0.0.1:8080/app1/


</VirtualHost>


images and css files are shown correctly now. New problem: I'm loosing the session.
After I hit the Login button, I'm back on the frontpage an get the message: session expired, please login again. looking to the cookies shows me: JSESSION Cookie path: mydomain.com/app1
Traxxas10
 
Posts: 7
Joined: 16. October 2018 10:33
XAMPP version: 1
Operating System: ubuntu 16.04

Re: Apache VirtualHost to Glassfish Applications

Postby Nobbie » 16. October 2018 15:43

Traxxas10 wrote:I could fix it a bit more after removing some /


See my posting above, thats what i already did before...

You loose the session data due to cookie problems, that should be handled in the tutorial about reverse proxies as well. If not, i cannot test it any further here, you have to solve it anyway on yourself.

P.S.: I already found it

If your backend server uses cookies, you may also need the ProxyPassReverseCookiePath and ProxyPassReverseCookieDomain directives. These are similar to ProxyPassReverse, but deal with the different form of cookie headers. These require mod_proxy from Apache 2.2 (recommended), or a patched version of 2.0.
Nobbie
 
Posts: 10541
Joined: 09. March 2008 13:04

Re: Apache VirtualHost to Glassfish Applications

Postby Traxxas10 » 16. October 2018 16:39

ok thank you. I tried a lot, the cookie path is now correct but it's still not possible to use the application - i dont know why...

if I change the Proxypass back to: "ProxyPass /app1 http://127.0.0.1:8080/app1"
and remove the rewrite things, I can call: www.domain1.com/app1 and use the whole application with no problems.

I added a simple redirect and can reach my app under www.domain.com now

now config:
Code: Select all
<VirtualHost *:80>
        ServerName domain.com
        ServerAlias www.domain.com


        Redirect / /app1

        ProxyPass /app1 http://127.0.0.1:8080/app1
        ProxyPassReverse /app1 http://127.0.0.1:8080/app1
</VirtualHost>


it's not what I prefere, but it works with an ugly "/app1" in the URL.

Nevertheless, I'll thank you very much for your time and great help!
Traxxas10
 
Posts: 7
Joined: 16. October 2018 10:33
XAMPP version: 1
Operating System: ubuntu 16.04


Return to Apache

Who is online

Users browsing this forum: No registered users and 3 guests