Skip to content

Room for another reverse-proxy?

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"

Comments On This Entry

  1. [gravitar] Dan Carley

    Nginx's rewrite module is pretty powerful.

    No need to reinvent the wheel :)

  2. [author] Steve Kemp

    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.

  3. [gravitar] Andrew

    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.

  4. [gravitar] Np237

    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.

  5. [author] Steve Kemp

    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 :)

  6. [gravitar] Robert

    (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.

  7. [gravitar] XANi

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

  8. [gravitar] poisonbit

    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

  9. [gravitar] Nux

    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.