1

I'm setting up mod_jk for Apache to use with Tomcat and there are two issues I've ran into.

SSL

I have SSL enabled on Apache and all traffic is going through HTTPS, including the requests forwarded to Tomcat. Does Tomcat also need to be configured for SSL in any way or does Apache handle it completely? Everything I have found doesn't say Tomcat needs any configuration but I'm getting the following error in Tomcat which could be related.

IllegalArgumentException: Invalid character found in method name. HTTP method names must be tokens

appBase/mounting

My appBase in Tomcat is the typical "path/to/webapps" and when Apache forwards a request it naturally gives it the full path. However, since I only want to forward certain URLs to Tomcat, my JkMount looks something like "JkMount /apps/* worker1". The problem is that Tomcat will be looking for the applications in "path/to/webapps/apps/" which is not the directory the applications get deployed in. Using RewriteRule to remove the "apps" from the path I assume would cause it to not be forwarded to Tomcat. I'm not sure if there are any better solutions.

1 Answer 1

0

all traffic is going through HTTPS, including the requests forwarded to Tomcat

That's not entirely true. If you are using mod_jk the requests from Apache to Tomcat use AJP, a non encrypted binary protocol. The error you find in the logs means that something is connecting to the HTTP connector of Tomcat using a binary protocol. Make sure that you have an AJP connector in your Tomcat configuration:

<!-- Define an AJP 1.3 Connector on port 8009 -->
<Connector port="8009" protocol="AJP/1.3" redirectPort="8443" />

and you use the same port (e.g. 8009) instead of the HTTP port in mod_jk's worker.properties.

Regarding the JkMount directive, it is not possible to rewrite the URI Path using mod_jk: if Apache gets a request form https://example.com/apps/foo/bar it will ask Tomcat for /apps/foo/bar.

If you want Apache to retrieve /foo/bar instead you can use mod_proxy_ajp instead of mod_jk:

ProxyPass "/apps" "ajp://backend.example.com:8009"

However I would advise against rewriting the URI Path of the request. If you do it you'll have problems like this one.

3
  • I've solved the mounting part, however can't find what's causing that error. Apache is properly using the AJP protocol and using the correct ports.
    – stripies
    Feb 22, 2021 at 19:05
  • Usually the error message contains the first bytes of the request, so you can find out what happened. A TLS handshake, e.g. starts with the bytes \x16\x03. Feb 22, 2021 at 19:47
  • Nevermind, mistake on my part. I was focusing on the server and didn't see I was connecting from port 8080 from the client. Also to anyone else that may have a similar problem with the mounting, The best solution, which I was trying to avoid, is to use JkMount for each individual application.
    – stripies
    Feb 22, 2021 at 19:48

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .