viviotech / mod_cfml

Mod_cfml is a community-driven suite of programs that automatically configures Tomcat hosts to match hosts created in Apache or IIS. Mod_cfml removes the need to configure web sites twice - once in your web server and again in Tomcat - and performs this task automatically for you.
GNU Lesser General Public License v3.0
23 stars 16 forks source link

Apache execution order with mod_proxy and mod_cfml #6

Closed Wyox closed 9 years ago

Wyox commented 9 years ago

Hi,

I've been trying to setup a Lucee + Apache stack for a while and I kept running into problems where my VirtualHost configuration wasn't passed through to the Tomcat env. Everytime I did the request I saw the welcome screen of Lucee.

Initial I thought I had wrongly configured my env and even tried to follow the instructions from here by the letter. After some debugging sessions later I noticed that Tomcat7 never received the 'X-Tomcat-DocRoot' header indicating it must be on the Apache side of it.

After narrowing down the problem I found that Apache has a certain way of handling their module execution order. I added some logs into the mod_cfml.c to check if the request is actually being passed to Tomcat7 and noticed that it never reached the hook at all. Turning off mod_proxy made the .cfm requests show up in the apache logs. Turning mod_proxy on again and these requests disappeared from my apache logs.

This all made sense since my proxy.conf looks like this and is only passing through .cfc / .cfm files.

<IfModule mod_proxy.c>
    <Proxy *>
        Allow from 127.0.0.1
    </Proxy>
    ProxyPreserveHost On
    ProxyPassMatch ^/(.+\.cf[cm])(/.*)?$ ajp://localhost:8009/$1$2
</IfModule>

I thought this would be related to the execution order of Apache modules in some case and mod_proxy stopping any other modules from executing further mods. To test this I slightly modified mod_cfml.c and compiled it against 2.4. Changes can be found in a fork I made here. These changes fixed the issue I had.

I'm doing this on a machine generated by a Dockerfile running the following:

Apache2.4/10 Lucee 4.5.1.0 (Using the Lucee Installer with Tomcat7)

If required I can add my Dockerfile to this issue to reproduce the issue and a Dockerfile with the issue fixed.

utdream commented 9 years ago

Ivo,

This is awesome! I'm extremely impressed you took the time to not only evaluate the problem so thoroughly, but also took the time to review the code and submit a patch! That's what OSS is all about!

I'd like to have Paul Klinkenberg take a look at your changes since he is far more familiar with the c-code than I am. I've pinged him about your message here and asked him to take a look when he has some time.

Thank you!

Wyox commented 9 years ago

Hey Jordan,

Thank you and you are very welcome, the addition might be of good use for many of us using mod_cfml.

I just got frustrated by the fact something didn't work out as planned since the instructions to install were incredibly simple to use. I just wanted to find out the problem further and initially thought it was a configuration error until I just looked deeper into the issue itself.

I don't have much C knowledge myself either but I the fix is really small and shouldn't give much trouble. If everything is alright I can submit a pull request so the code gets merged.

paulklinkenberg commented 9 years ago

Hi Ivo, Like Jordan said, thanks for taking the time to look into this and contribute! The proposed fix has an unfortunate turnaround: on my environment, using mod_jk, I am now seeing the exact error you described before you fixed it :-/ But, it is very helpful to know that this problem exists. Probably the safest way to fix it, is by setting the hook handler order to a lower value. I proposed this in a pull request I did just now into your repo. If you want to, then please pull it in, and send it through to Jordan's repo. After all, it was your idea and your fix :) Kind regards, Paul

Wyox commented 9 years ago

Hey Paul,

Changing the order like that never crossed my mind, might even be better! Initially I thought of extending the aszSucc[] structure with both "mod_proxy" and "mod_jk" but that might leave out some other proxies.

I checked if your change worked with mod_proxy on my env and it does. I'll submit a pull request.

Thanks for making mod_cfml and the quick support on this!