title: Apache is reporting 502 bad gateway on reverse proxy to CouchDB
body: <p>I'm trying to set up a reverse proxy to CouchDB using Apache on an instance of Ubuntu Server 12.04. I have been accessing CouchDB directly through port 5984 but the lack of compression on responses is causing too much network usage, and the reverse proxy allows me to enable gzip compression.</p>
  
  <p>So far, I've set the configuration file for my site as so:</p>
  
  <pre><code># /etc/apache2/sites-available/SITE_NAME
  &lt;VirtualHost *:80&gt;
      ServerAdmin *****
      ServerName *****
      ServerAlias *****
      RewriteEngine On
      RewriteOptions Inherit
      RewriteRule ^/couch/(.*) http://%{HTTP_HOST}:5984/$1 [P]
      ProxyPass /couch/ http://localhost:5984/ nocanon
      ProxyPassReverse /couch/ http://localhost:5984/
      DocumentRoot /var/www/*****/current/public
      &lt;Directory /var/www/*****/current/public&gt;
              Allow from all
              Options -MultiViews
      &lt;/Directory&gt;
  &lt;/VirtualHost&gt;
  </code></pre>
  
  <p>At this point, I can access CouchDB through the reverse proxy using curl, e.g.</p>
  
  <pre><code>curl -X GET http://MY_SERVER_ADDRESS/couch/_all_dbs
  </code></pre>
  
  <p>and I get successful responses every time.</p>
  
  <p>However, the primary client of this proxy is an iOS device, and whenever I run the same request using <code>NSURLConnection</code> I'm getting a <code>502 Bad Gateway</code> error. With this response:</p>
  
  <blockquote>
    <h1>Proxy Error</h1>
    
    <p>The proxy server received an invalid response from an upstream server.<br />
    The proxy server could not handle the request <em>GET&nbsp;/couch/DATABASE_NAME/_changes</em>.<p>
    Reason: <strong>DNS lookup failure for: MY_SERVER_ADDRESS</strong></p></p>
    
    <p><hr></p>
    
    Apache/2.2.22 (Ubuntu) Server at MY_SERVER_ADDRESS Port 80
  </blockquote>
  
  <p>I've gone so far as to copy and paste the <strong>exact</strong> URL and header fields from the <code>NSURLRequest</code> into a curl request but I can't replicate the error in the terminal. I've also tried <a href="https://stackoverflow.com/questions/169453/bad-gateway-502-error-with-apache-mod-proxy-and-tomcat">changing timeout values</a> in the configuration file but it makes no difference.</p>
  
  <p>N.B. This occurs on both an iOS device over the local network, and in the iOS simulator running on the same machine as the server (the server is a Virtual Machine running inside Virtual Box).</p>