Use apache as frontend to Glassfish

1.2k views Asked by At

Is it possible at all to do what I'm trying to do?

I have a domain - example.com - installed on a webserver Ubuntu 16.04/Apache.

Behind Apache I'm running a standard Glassfish (Payara actually) on standard port 8080.

On Payara I have a webapp - myWebapp - deployed on root context /

when i point my broser directly to port 8080 it shows my web app as i expect:

http://example.com:8080/ => webapp shown.

1) first i want to hide my Payara behind apache and make sure when people write

http://example.com/ the are redirected to

https://example.com => myWebapp is shown.

This part works using AJP and my certificates are all in place.

In my default.conf in the

<VirtualHost *:80>

have inserted the following line:

Redirect permanent / https://example.com

it takes care of the redirection to HTTPS. But i'm in doubt if this is the right way to do it.

Everything else in the conf file is standard.

in my ssl.conf file in the

<virtualHost *.443>

I have inserted

ServerName example.com 

and paths to SSL certificates. It's working as expected.

further more i have added

ProxyPass / ajp://127.0.0.1:8009
ProxyPassReverse / ajp://127.0.0.1:8009

Again, this works well. If i write

http://example.com

I'm redirected to

https://example.com/ => myWebapp is shown.

This is perfect.

but if i write

http://example.com/phpmyadmin

for instance I'm not shown the phpmyadmin page.

How can i accomplish this and is it possible at all?

thanks for any help.

Kim

1

There are 1 answers

6
toongeorges On BEST ANSWER

You have a conflict in the following configuration:

ProxyPass / ajp://127.0.0.1:8009
ProxyPassReverse / ajp://127.0.0.1:8009

This sends all http requests, also http://example.com/phpmyadmin to your Payara server

What you need instead is something like

ProxyPass /myWebapp ajp://127.0.0.1:8009
ProxyPassReverse /myWebapp ajp://127.0.0.1:8009

so that only relative URLs that start with /myWebapp are redirected to your Payara server and /phpmyadmin is still hosted by Apache.

The Apache documentation mentions:

Only specific URIs can be proxied, as shown in this example:

ProxyPass "/images"  "http://www.example.com/"
ProxyPassReverse "/images"  "http://www.example.com/"

In the above, any requests which start with the /images path with be proxied to the specified backend, otherwise it will be handled locally.