0

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

OndroMih
  • 7,280
  • 1
  • 26
  • 44
Kim Gabrielsen
  • 435
  • 2
  • 6
  • 21

1 Answers1

0

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.

toongeorges
  • 1,844
  • 17
  • 14
  • Ok, so the user has to write http://example.com/myWebApp in order to hit my application? – Kim Gabrielsen Sep 12 '17 at 13:06
  • In this solution yes – toongeorges Sep 12 '17 at 13:24
  • You could add `RedirectMatch ^/$ http://www.example.com/myWebApp` to the Apache config to redirect `http://www.example.com` to `http://www.example.com/myWebApp`. – toongeorges Sep 12 '17 at 13:28
  • Also take a look at https://stackoverflow.com/questions/26848945/exclude-an-alias-from-virtualhost-proxypass it seems your question has been answered there before. – toongeorges Sep 12 '17 at 13:40
  • thank you for taking your time. I will look into the details of this. And maybe learn a little more about Apache in the process. – Kim Gabrielsen Sep 12 '17 at 14:03
  • Note also that Apache configuration is read and applied top-to-bottom. So you should, in theory, be able to have a specific `ProxyPass` directive for phpmyadmin and then have a catchall directive for root (`/`) ***underneath***. – Mike Sep 12 '17 at 14:06