About Archive Tags RSS Feed

 

Room for another reverse-proxy?

17 September 2010 21:50

Like many people I use Apache's mod_proxy to proxy from *:80 to a bunch of servers running upon 127.0.0.1:XX.

(I've mentioned this too often; but in short I have a bunch of sites all running with thttpd under their own UID).

Why do I use apache soley as a reverse proxy, instead of pound, varnish, nginx, or lighttpd? After all it is pretty heavy-weight. Well the answer to that is that I have a bunch of mod_rewrite rules.

So I'm wondering, could I drop apache if I were to hack together a simple network proxy that would listen upon port 80, reading requests, and directing them to local servers? The answer to that is plainly "yes". There are many reverse-proxies around and writing them isn't hard.

So what would be the point? Imagine a reverse-proxy that understood mod_rewrite rules. That would rock.

In short we'd have to define three things:

  • Matching vhost name.
  • Destination to proxy to.
  • (Optionally) the mod_rewrite rules

Given something like this:

LISTEN 1.2.3.4:80

host example.net or host www.example.net
{
   #redirect traffic here
   proxy_to 127.0.0.1 1011

   RewriteRule /about /cgi-bin/index.cgi
}

When the proxy received an incoming request to http://example.net/about it would actually send the request /cgi-bin/index.cgi to the host 127.0.0.1:1011.

That seems neither too complex nor too impossible.

The hard part would be emulating mod_rewrite 100%. Especially chained requests. I would be willing to write the trivial version, but I suspect the full emulation would be a job of diminishing returns. Am I right?

ObSubject: You crossed the line first, sir. - "The Dark Knight"

| 9 comments

 

Comments on this entry

icon Nux at 17:30 on 18 September 2010
http://www.nux.ro

To be honest, having a reverse proxy capable of Apache rewrite rules would be pretty sweet.
Porting/implementing something like this in Nginx would be AWESOME (yes, I know that it already has powerful rewrite rules) but it also could take a long time and perhaps there is a reason nobody tried/succeeded to do it yet.

I for one could enjoy very much a small/minimalistic perl daemon can understand Apache rewrite rules. I'm sure such a project wouldn't go unnoticed.

icon poisonbit at 16:35 on 18 September 2010
http://poisonbit.wordpress.com

I think it is a marvelous idea.

Said that, if the idea is to be fully compatible, maybe that your invent needs to XSload mod_rewrite.c :)

I wish that light reverse proxy with full apache > 1.3 rewrite compatibility.

Load existing mapfiles and existing apache2 prg's, could be a plus.

Greetings

icon XANi at 13:00 on 18 September 2010
http://devrandom.pl

Tbh. I would rather have some kind of converter that converts from mod_rewrite format to lighttpd/nginx rules

icon Robert at 11:33 on 18 September 2010

(If I were ignoring your mod_rewrite desires I would of course just say "use haproxy", but...)

If you want to get 100% compatibility with mod_rewrite, you might be best to just rip the heart out of mod_rewrite itself into an abstract url-rewriting library. Who knows, the mod_rewrite maintainers might be interested in factoring out the central rewrite engine.

icon Steve Kemp at 10:28 on 18 September 2010
http://www.steve.org.uk/

I think perhaps I'm not making my point clearly enough:

  • Yes there are other things working as reverse-proxies.
  • Their rules are different enough that mass-conversion is a pain.

I think you've all convinced me that either my suggestion of a mod_rewrite syntax-port, rather than anything else, is not something that seems useful to others.

For the moment I'll keep Apache2 and I will example using nginx instead in the near future.

I do personally think that mod_rewrite is the defacto standard and having to reinvent the wheel by porting such rules to different servers is a bigger waste of time than having a proxy.

That said I can understand the argument :)

icon Np237 at 09:46 on 18 September 2010
http://np237.livejournal.com/

I really have the feeling you are reinventing the wheel. Things like nginx and lighttpd are perfect for this kind of use, and they have powerful rewrite engines.

icon Andrew at 19:44 on 17 September 2010
http://dollarprivacy.blogspot.com

As mentioned nginx is pretty powerful as reverse-proxy(i think it's a defacto standard right now). From my experience with migration from apache to nginx rewrite rules almost the same(little difference in keywords) won't take much time to fix and pretty straight-forward.

icon Steve Kemp at 18:24 on 17 September 2010
http://www.steve.org.uk/

The problem is that Apache's mod_rewrite is the defacto standard for such things.

Anything and everything from wordpress, to phpbb, and mediawiki includes such rules. Nothing else, except for Apache/Apache 2.x, understands them.

Yes other servers have similar features. But no that doesn't make it necessarily easy to convert.

icon Dan Carley at 18:21 on 17 September 2010

Nginx's rewrite module is pretty powerful.

No need to reinvent the wheel :)