1

I have configured a server where lies several domains, and more than one of them have a ajp13-worker associated to it. The configuration file looks like that:

<VirtualHost *:80>
        ServerAdmin my@email
        ServerName mydomain
        ServerAlias www.domain
        DocumentRoot /home/kleber/www/loja
        JkMount /app* ajp13_worker
        ...
</VirtualHost>

when I deploy some webapps like appOne.war and appTwo.war to my tomcat webapps directory, I can access them using something like that: https://mydomain/appOne and https://mydomain/appTwo.

How I could configure the mod-jk plugin with the tomcat and apache to allow me access some of this webapps as https://mydomain/ only? In a way I could define one webapp per domain using the mod-jk ajp13-worker to be the root path, and allowing me continuing to access the webapps appOne.war and appTwo.war as before.

update

<VirtualHost *:80>
        ServerAdmin ...
        ServerName ...
        ServerAlias ...
        DocumentRoot /home/kleber/www/loja
        JkMount /app* ajp13_worker

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        RewriteEngine on
        RewriteCond %{SERVER_NAME} =... [OR]
        RewriteCond %{SERVER_NAME} =...
        RewriteRule ^ https://%{SERVER_NAME}%{REQUEST_URI} [END,NE,R=permanent]
</VirtualHost>
Kleber Mota
  • 93
  • 1
  • 7

2 Answers2

0

You need an internal rewrite:

<VirtualHost *:80>
    ServerAdmin my@email
    ServerName loja-de-software.net.br
    ServerAlias www.loja-de-software.net.br
    DocumentRoot /home/kleber/www/loja
    JkMount /app* ajp13_worker

    RewriteEngine  on

    RewriteCond %{HTTP_HOST} loja-de-software.net.br
    RewriteRule /(.*) /appOne/$1 [PT,END]

</VirtualHost>
Gerard H. Pille
  • 2,569
  • 1
  • 13
  • 11
  • Is there a problem use 2 RewriteRules for the same VirtualHost? Like shown in the update in the question, I already have one, inserte there by the certbot/let's encrypt tool. Can I add another without cause any issues? – Kleber Mota Apr 10 '20 at 13:10
  • Yes, there is a problem. The rule you have catches every request for two domains and ends the rewriting. – Gerard H. Pille Apr 10 '20 at 13:26
  • Is there any workaround for that? Or any solution not involving redirect? – Kleber Mota Apr 10 '20 at 13:44
  • Sure, and I'd like to repeat that there is no redirecting in the new rule. See edited answer. – Gerard H. Pille Apr 10 '20 at 14:03
  • The rule added by the "certbot" does send a redirect to HTTPS. This configuration doesn't catch port 443. – Gerard H. Pille Apr 10 '20 at 14:08
  • I finally tried this solution, but when I add this lines to my virtualhost configuration file, I am not able to start apache, due error on this lines. 2 questions: 1) `appOnedomain` should be the complete domain name, with the app name (`loja-de-software.net.br/appHello`) or something else? and 2) if I define this `JkMount /app* ajp13_worker` do i should use `/app*` or `/appHello` in the redirect rule? – Kleber Mota Apr 16 '20 at 22:06
  • Edited my answer, "=domain", not "= domain" in the RewriteCond. "/app*" may be OK for JkMount, but probably not in a rewriterule. "/app.*" maybe? – Gerard H. Pille Apr 17 '20 at 03:55
  • Edited once more, probably the END flag is needed too. – Gerard H. Pille Apr 17 '20 at 08:48
  • But instead of `appOnedoman` and `appTwodomain` I should use the full domain name (` loja-de-software.net.br` ) or the name of the webapp (for instance `appHello` or something)? – Kleber Mota Apr 17 '20 at 10:27
  • If you had to answer that yourself, what would it be? – Gerard H. Pille Apr 17 '20 at 10:46
  • I've added the two domains to the ServerAlias directive, otherwise the RewriteCond's made no sense. Once more: why the redirect to https? What happens with the https requests? – Gerard H. Pille Apr 17 '20 at 10:52
  • I not access the webapps using a subdomain (something like `appOnedomain.mydomain.com`). I have one ServerAlias configured, to allow access to `www.loja-de-software.net.br` and `loja-de-software.net.br`. I do not create a new alias for each webapp I deploy; I just do it, and after I can access them as a path like `loja-de-software.net.br/appOne` or `www.loja-de-software.net.br/appOne`. – Kleber Mota Apr 18 '20 at 19:39
  • So, if you can do that, then what is your problem? – Gerard H. Pille Apr 18 '20 at 20:24
  • I want deploy the webapp and access it as `loja-de-software.net.br` and not as `loja-de-software.net.br/appOne`. the RewriteRule suggested before do not acomplish this result. – Kleber Mota Apr 18 '20 at 20:33
  • And the current one? – Gerard H. Pille Apr 18 '20 at 23:02
  • Same result: access via `/appOne` only, `/` just list the directory. This works alongside the existing RewriteRule? I cannot remove those due it's essential to the https access (It was not me that put that there, but it was added automatically by the certification utilitary) – Kleber Mota Apr 19 '20 at 11:08
0

If you want to make one of the webapp available on the root context, you can rename the war file to ROOT.war and redeploy. That used to work on tomcat8 at least...

alxgomz
  • 1,630
  • 1
  • 11
  • 14