Apache and rLucee doesn't play well with virtual host rewrites

204 views
Skip to first unread message

Tom Chiverton

unread,
May 22, 2015, 6:22:49 AM5/22/15
to lu...@googlegroups.com
I'm using the default Apache connector, so there are a bunch of ProxyPassMatch directives at the end of the httpd.conf along with hooks for the Perl module.

I'm having an issue though, where I want to use a redirect on a particular virtual host to direct people away from an older version :
redirectmatch /landing/.* /website/

Because mod_proxy always trumps mod_redirect, this redirect only works for non-.cfm files :-/ .cfm requests still go to Lucee, which in this case triggers a file not found error because it's an old site and we removed the files (and wouldn't want them run anyway).

I can work around this for now by adding
        ProxyPassMatch ^/landing.* !
to the main Apache config, but this isn't a good fix - in future in other virtual hosts we may want CFML content in a folder called landing.
Adding it just to the virtual host doesn't help, because it's still picked up by the global proxy.

I think this would be fixed if Lucee used mod_rewrite with it's proxy ability, instead of mod_proxy directly, because the virtual host's rewrite rules would be invoked.

Is there some deeper inner reason why mod_proxy is used rather than mod_rewrite ? Maybe to do with the Perl module ?

Jordan Michaels

unread,
May 22, 2015, 3:16:00 PM5/22/15
to lu...@googlegroups.com
> Is there some deeper inner reason why mod_proxy is used rather than
> mod_rewrite ? Maybe to do with the Perl module ?

Nope. Use whatever works in your environment. The only thing the perl module does is modify the incoming request header for extensions that it handles. Use whatever connection method works for you.

Note that Paul Klinkinberg has been making some significant updates to the mod_cfml modules, including significant speed improvements to the valve, as well as a native C-module for Apache (mod_perl will no longer be required), and it's faster as well.

-Jordan
--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/lucee/ee83a4a3-d201-44ec-b31b-6f503fcb46e7%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Tom Chiverton

unread,
May 23, 2015, 5:44:43 AM5/23/15
to lu...@googlegroups.com
Should the install be changed to use mod_rewrite by default instead then ?
I'll try updating our Apache this weekend, as I had other work planned anyway.

You received this message because you are subscribed to a topic in the Google Groups "Lucee" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/lucee/tJt1c4FwnMg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to lucee+un...@googlegroups.com.

To post to this group, send email to lu...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.



--
Tom

Tom Chiverton

unread,
May 25, 2015, 8:09:18 AM5/25/15
to lu...@googlegroups.com
So it looks like it's not quite as simple as replaceing the proxypass block with

RewriteEngine On
ProxyPreserveHost On
ProxyPassReverse / http://127.0.0.1:8888/
RewriteRule ^/(.+\.cf[cm])(/.*)?$ http://127.0.0.1:8888/$1$2 [P,QSA]
RewriteRule ^/(.+\.cfml)(/.*)?$ http://127.0.0.1:8888/$1$2 [P,QSA]

because this just serves the bare CFML templates. I'm not sure why, because if you place the same directives inside the VirtualHost, it works great !

Any other Apache users know why this should be ?

Tom Chiverton

unread,
May 25, 2015, 8:21:12 AM5/25/15
to lu...@googlegroups.com
Doh, of course rewrite rules don't inherit. But if the server config does


ProxyPreserveHost On
ProxyPassReverse / http://127.0.0.1:8888/

<Directorymatch /wwwroot/clients/*>
RewriteEngine On
RewriteOptions Inherit

RewriteRule ^/(.+\.cf[cm])(/.*)?$ http://127.0.0.1:8888/$1$2 [P,QSA]
RewriteRule ^/(.+\.cfml)(/.*)?$ http://127.0.0.1:8888/$1$2 [P,QSA]
</Directorymatch>

Then Lucee returns a 404 error for the webroot, twice e.g.

/wwwroot/clients/r/roadrunner/wwwroot/clients/r/roadrunner/website/index.cfm
instead of
/wwwroot/clients/r/roadrunner/website/index.cfm

could this be something in the CFML Perl module ? Seems unlikely...

Tom

Chris Blackwell

unread,
May 26, 2015, 7:55:01 AM5/26/15
to lucee
Tom, 

why not just do your redirect with mod_rewrite instead

RewriteEngine on
RewriteRule   "^/landing/(.*)$"  "/website/$1"  [R=302,L]




--
You received this message because you are subscribed to the Google Groups "Lucee" group.
To unsubscribe from this group and stop receiving emails from it, send an email to lucee+un...@googlegroups.com.
To post to this group, send email to lu...@googlegroups.com.

Tom Chiverton

unread,
May 26, 2015, 8:56:36 AM5/26/15
to lu...@googlegroups.com
I though I had explained. mod_proxy in the server config is run before mod_rewrite in the virtual host.
If the server config was mod_rewrite too, this wouldn't be an issue.

Tom

Tom Chiverton

unread,
May 26, 2015, 9:37:36 AM5/26/15
to lu...@googlegroups.com
For posterity, accessing through mod_rewrite is fine, but to get the paths to work out, either you have to hard code the web root path before '$1', or create a conf/lucee.conf like the bellow that you add to each virtual host.

We're probably going to do the later, but it's not a good general replacement for mod_proxy.
Which might explain what it's done with mod_proxy. mod_proxy is given the URL path so that's great when sent to Tomcat with the correct Host header, but mod_rewrite in a <DirectoryMatch /*> (with "options Inherit" so virtual hosts see it) gets the full file system path.

conf/lucee.conf:

ProxyPreserveHost On
ProxyPassReverse / http://127.0.0.1:8888/
RewriteEngine On

RewriteRule ^/(.+\.cf[cm])(/.*)?$ http://127.0.0.1:8888/$1$2 [P,QSA]
RewriteRule ^/(.+\.cfml)(/.*)?$ http://127.0.0.1:8888/$1$2 [P,QSA]

Tom

Chris Blackwell

unread,
May 26, 2015, 9:53:09 AM5/26/15
to lucee
Hi Tom,

Sorry i hadn't spotted the difference in context between where the directives were being defined.

I do as you've suggested, and include lucee proxy configs in each vhost, where needed (as not all vhosts use lucee). 
I've never had a problem mixing mod_rewrite and mod_proxy within a vhost, and have always been able to use mod_proxy for sending requests to lucee and mod_rewrite for things like friendly urls


Peter Boughton

unread,
May 26, 2015, 10:01:48 AM5/26/15
to lu...@googlegroups.com
> this redirect only works for non-.cfm files :-/
> .cfm requests still go to Lucee, which in this case
> triggers a file not found error because it's an old
> site and we removed the files

onMissingTemplate

if ( cgi.request_uri.startsWith('oldplace') )
location( cgi.request_uri.replaceFirst('oldplace','newplace') , false , 301 );

Problem solved.


> Then Lucee returns a 404 error for the webroot, twice e.g.

Do you get the same thing when visiting Tomcat directly, or only when
going through Apache ?

What about if you send a non-CFML request to Tomcat (i.e. something
Lucee wont touch) - what path does it use?

Does it occur when you add the L flag to the rewrites to prevent any
other rules potentially interfering.

Also, do you *actually* have .cfml files and requests
for .cfc/with_path_info


> could this be something in the CFML Perl module ?

Try the new native C version Paul's doing and see if it still occurs?

Tom Chiverton

unread,
May 26, 2015, 10:13:13 AM5/26/15
to lu...@googlegroups.com, lu...@sorcerersisle.com
Rewriting / adding Application.cfc for every host isn't a good solution for us :-)
I'm following the new mod_cfml changes with interest. We don't restart often, but when we do it'll be important to get all the hosts back quickly.

Tom

Peter Boughton

unread,
May 26, 2015, 10:25:29 AM5/26/15
to lu...@googlegroups.com
You said you had an issue on a particular host to move away from an old
version, so using two lines of CFML to make it work will appease
clients and gives the time to investigate the appropriate config
changes to solve the wider issue.
Reply all
Reply to author
Forward
0 new messages