Fixes for apache set up -- use x-forwarded-host if it exists.

This change modifies the apache configuration and tweaks the update
ping logic to handle being behind apache. When behind apache,
the request.base is re-written to whatever is configured in the [proxy]
stanza.  As this is then 127.0.0.1, we need to checked X-Forwarded-Host
for the original hostname used in the request.

The fixes in setup_apache_setup.sh are minor and caught when staging
apache on the live devserver.

BUG=chromium-os:26451
TEST=Ran apache set up on my own host.  Used DUT and contacted my_ip:8082
and saw the hostname get written correctly and the DUT update.

Change-Id: Id7e2de7d6e3e2c2a5fdbc7e5054cab26fa7d6bbd
Reviewed-on: https://gerrit.chromium.org/gerrit/25262
Tested-by: Chris Sosa <sosa@chromium.org>
Reviewed-by: Scott Zawalski <scottz@chromium.org>
Commit-Ready: Chris Sosa <sosa@chromium.org>
diff --git a/autoupdate.py b/autoupdate.py
index 0badb91..cbe0a73 100644
--- a/autoupdate.py
+++ b/autoupdate.py
@@ -706,8 +706,14 @@
       Update payload message for client.
     """
     # Set hostname as the hostname that the client is calling to and set up
-    # the url base.
-    self.hostname = cherrypy.request.base
+    # the url base. If behind apache mod_proxy | mod_rewrite, the hostname will
+    # be in X-Forwarded-Host.
+    x_forwarded_host = cherrypy.request.headers.get('X-Forwarded-Host')
+    if x_forwarded_host:
+      self.hostname = 'http://' + x_forwarded_host
+    else:
+      self.hostname = cherrypy.request.base
+
     if self.urlbase:
       static_urlbase = self.urlbase
     elif self.serve_only: