title: Using Apache2 behind HAProxy is not working properly
body: <p>I'm using apache 2.2 on ubuntu 12.04 behind haproxy 1.5. My haproxy is listening on port 80 and apache is listening on port 8000. What I'm trying to do is that I want to forward any request that comes on haproxy with path "/test" to a my apache.</p>
  
  <p>I have an wordpress application hosted in "/var/www/test".</p>
  
  <p>The problem I'm facing is that if I try to access test app using <strong><a href="http://www.example.com/test" rel="nofollow">http://www.example.com/test</a></strong>, apache redirected it to <strong><a href="http://www.example.com:8000/test/" rel="nofollow">http://www.example.com:8000/test/</a></strong> .  Any idea why this is happening?. What am I missing?</p>
  
  <p>and here is the the configurations:</p>
  
  <p>ports.conf:</p>
  
  <pre><code>NameVirtualHost *:8000
  Listen 8000
  
  &lt;IfModule mod_ssl.c&gt;
      Listen 443
  &lt;/IfModule&gt;
  
  &lt;IfModule mod_gnutls.c&gt;
      Listen 443
  &lt;/IfModule&gt;
  </code></pre>
  
  <p>sites-available/default:</p>
  
  <pre><code>&lt;VirtualHost *:8000&gt;
          ServerName www.example.com
          ServerAdmin webmaster@localhost
          DocumentRoot /var/www
          &lt;Directory /&gt;
                  Options FollowSymLinks
                  AllowOverride None
          &lt;/Directory&gt;
          &lt;Directory "/var/www"&gt;
                  Options Indexes FollowSymLinks MultiViews
                  AllowOverride None
                  Order allow,deny
                  allow from all
          &lt;/Directory&gt;
  
          ErrorLog ${APACHE_LOG_DIR}/error.log
  
          LogLevel warn
  
          CustomLog ${APACHE_LOG_DIR}/access.log combined
  
   &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>haproxy.cfg:</p>
  
  <pre><code>frontend http-in
        bind *:80
        acl is_test path_beg /test
        use_backend test_backend if is_test
  
  backend test_backend
        balance roundrobin
        option forwardfor
        server Local localhost:8000 check
  </code></pre>
  
  <p>Also I figured out that $_SERVER['HTTP_X_FORWARDED_HOST'] is empty when i log it in index.php. Any idea why it's happening.</p>