Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a Ubuntu 12.04.3 server set up acting as DNS server (BIND9), web server (Apache2) and a reverse proxy server (haproxy). My goal is to have haproxy redirect to some of the other servers on the network, some of which I want to redirect to a 'sub URL' (Not sure that's the right term. Please see the example below)

user goes to "" > haproxy redirects to > ""

My DNS server is set up using wildcard subdomains, and right now if I go to it goes to the default apache page on the monitor server, but it would look a lot nicer and be a lot shorter to type if I could get it to direct to the /nagios page automatically. If I go to it works as expected, but it's a little redundant.

I spent a while searching for a solution, but I'm not having any luck finding the answer to my question. Does anyone have any idea if this is possible and if so how I might solve it? Here is my haproxy.conf file:

    log   local0
    log   local1 notice
    #log loghost    local0 info
    maxconn 4096
    #chroot /usr/share/haproxy
    user haproxy
    group haproxy

    log     global
    mode    http
    option  httplog
    option  dontlognull
    retries 3
    option redispatch
    maxconn 2000
    contimeout      5000
    clitimeout      50000
    srvtimeout      50000

frontend http-in
    bind 1:80

    acl host_apache hdr(host) -i
    acl host_monitor hdr(host) -i
    acl host_cloud hdr(host) -i

    use_backend apache if host_apache
    use_backend monitor if host_monitor
    use_backend cloud if host_cloud

backend apache
    server web3

backend monitor
    server monitor

backend cloud
    server cloud

If anyone has any other suggestions or a different program I could use to achieve my goal, I'm open to suggestions. I'm not using haproxy for any particular reason. I've tried pound too, but could not get it configured either.

Thanks for reading!


share|improve this question
I've not played with haproxy for a long time (if ever), but why not simply use Apache + modproxy to do the reverse proxying you are looking to do ? – davidgo Jan 31 '14 at 7:01
I've tried it once or twice before but could not get it working. Could you recommend a guide, or a configuration example? – Brigzzy Feb 1 '14 at 6:11

While I love HAProxy, I'd agree with davidgo that it's probably not the best tool for this job. I also think that Apache with multiple named vhosts and mod_rewrite to proxy requests to the necessary backend are the way to go.

Listen 80
NameVirtualHost *:80

<VirtualHost *:80>
  RewriteEngine on
  ProxyPreserveHost On
  RewriteRule ^/(.*)$$1 [P]

<VirtualHost *:80>
  RewriteEngine on
  ProxyPreserveHost On
  RewriteRule ^/(.*)$$1 [P]

Depending on your applications on the backend, the rewrites may or may not work exactly like you are expecting. For example, if nagios is expecting that it's resources are located under a root dir of /monitor, and it links to things like /monitor/someurl, then your rewriting will cause the URL to end up at /monitor/monitor/someurl by the time it hits your server. That could probably be overcome by another RewriteRule, or a little bit of regex in the current one.

You could also just use straight mod_proxy with ProxyPass directives instead of mod_rewrite (which, in this case, is also utilizing mod_proxy)

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.