Search code examples
apachemod-rewritevirtualhostmod-proxy

Why does my page page return blank when using a server name with mod_rewrite?


I am using Apache, mod_rewrite, mod_pagespeed, and mod_proxy.

When accessing my page via IP (10.10.10.12:80), it successfuly rewrites me to 10.10.10.12:81 and then proxies me to an external server (10.10.10.13).

When accessing my page via DNS name (www.example.com), it returns a blank page. Viewing source code shows that my pagespeed configurations applied but my JS doesn't render and nothing shows up.

Below is the relevant code in my configuration:

<VirtualHost *:80>
  ProxyRequests off
  ServerAdmin xxx@xxx.com
  DocumentRoot /var/www/html

  RewriteEngine On
  RewriteLog "/home/dvanpham/rewrite.log"
  RewriteLogLevel 3

  #Directs escaped fragment code to an external rendering server
  RewriteCond %{QUERY_STRING} ^_escaped_fragment_=(.*) [NC]
  RewriteRule .* http://10.10.111.54:82/?page=http://10.10.111.54:81/#!%1 [NE,P,L]

  #Directs all other traffic to port 81, which then sends traffic to 2 other servers
  RewriteRule ^(.*)$ http://10.10.111.54:81$1 [NE,P]

  RewriteCond %{REQUEST_METHOD} ^(TRACE|TRACK)
  RewriteRule .* - [F]
</VirtualHost>

<VirtualHost *:81>
  ProxyRequests off
  <Proxy balancer://regscluster>
    # BalancerMember http://10.10.112.47:8280
    BalancerMember http://10.10.112.48:8280
    Order Deny,Allow
    Deny from none
    Allow from all
    ProxySet lbmethod=byrequests
  </Proxy>
  ProxyPass / balancer://regscluster/
</VirtualHost>

<VirtualHost *:82>
  ProxyRequests off
  <Proxy balancer://nodecluster>
    BalancerMember http://10.10.111.56:8080
    BalancerMember http://10.10.111.57:8080
    Order Deny,Allow
    Deny from none
    Allow from all
    ProxySet lbmethod=byrequests
  </Proxy>
  ProxyPass / balancer://nodecluster/
</VirtualHost>

Please let me know if there is any more information I can provide or if you have any insight into this issue!

EDIT: It looks like the issue is specifically related to mod_pagespeed and mod_rewrite when using the domain name.


Solution

  • The issue was that mod_pagespeed was listening for ProxyPass and rewriting the URLs accordingly but did not listen to RewriteRule.

    Setting

    "ModPagespeedMapOriginDomain http://localhost *.domain.com"

    did the trick.