Acralyzer with Wildcard DNS

Average: 5 (1 vote)

The purpose of this setup is to:

  • Receive application crash reports to URL of the form yourappname.acra.example.com
  • Create a virtual host like acra.example.com and redirect it to Acralyzer interface
  • Force SSL for Acralyzer interface

Prerequisites 

  1. working Apache configuration with mod_rewrite and mod_proxy enabled.
  2. Wildcard DNS for the domain you are going to use
  3. Acralyzer. Instructions on how to setup acralyzer can be found here.

Create a new virtual host file for Apache.

For Redhat based distributions this would be under /etc/httpd/conf.d/ for example /etc/httpd/conf.d/acra.example.com.conf 
For Debian based distributions this would be under /etc/Apache2/sites-available/ for example /etc/Apache2/sites-available/acra.example.com

Application crash report receiver

Listen to wildcard hostname and send report to locah acra-storage database via reverse proxy

# Virtual host name
ServerName 0.acra.example.com
# Wildcard virtual host name
ServerAlias *.acra.example.com
# Enable rewrite engine
RewriteEngine On
# Get the first element from the http host request
RewriteCond %{HTTP_HOST} ^([^\.]+)\.acra\.example\.com$ [NC]
# Forward to couch db to localhost using hostname part of http request as db name
RewriteRule ^/(.*)$ http://localhost:5984/acra-%1/_design/acra-storage/_update/report/$1 [P]

How does it work:

RewriteCond %{HTTP_HOST} ^([^\.]+)\.acra\.example\.com$ [NC]

grabs hostname from the host part of the http request. Hostname is now available in %1

RewriteRule ^/(.*)$ http://localhost:5984/acra-%1/_design/acra-storage/_update/report/$1 [P]

The request is forwarded via reverse proxy to the local couch db instance replacing %1 with hostname part of http request
For example myapp.acra.example.com will be forwarded to localhost:5984/acra-myapp/_design/acra-storage/_update/report/

Acralyzer interface

Create a redirect to acralyzer interface and then forward the request via reverse proxy to local couch db instance.

This is a simple 301 redirect from acra.example.com to acra.example.com/acralyzer/_design/acralyzer/index.html

RewriteCond %{REQUEST_URI} ^/$
RewriteRule (.*) /acralyzer/_design/acralyzer/index.html [R=301,L][/Apache_conf]

Access to Futon is blocked by denying access to _utils

<Location /_utils>
   Deny from all
</Location>

Finally the request is forwarded to local couch db instance

   ProxyRequests Off
   <Proxy *>
      Order deny,allow
      Allow from all
   </Proxy>
   ProxyPass / http://localhost:5984/
   ProxyPassReverse / http://localhost:5984/

Redirect to SSL

<VirtualHost *:80>
   ServerName acra.example.com 
   Redirect permanent / https://acra.example.com/
</VirtualHost>

Sample virtual host file

<VirtualHost *:80>
   ServerName acra.example.com 
   Redirect permanent / https://acra.example.com/
</VirtualHost>
<VirtualHost *:443>
   ServerName acra.example.com
   RewriteEngine On
   RewriteCond %{REQUEST_URI} ^/$
   RewriteRule (.*) /acralyzer/_design/acralyzer/index.html [R=301,L]
   <Location /_utils>
      Deny from all
   </Location>
   ProxyRequests Off
   <Proxy *>
      Order deny,allow
      Allow from all
   </Proxy>
   ProxyPass / http://localhost:5984/
   ProxyPassReverse / http://localhost:5984/
   SSLEngine on
   SSLCertificateFile    /etc/Apache2/ssl/Apache.pem
   SSLCertificateKeyFile /etc/Apache2/ssl/Apache.key
</VirtualHost>
 
<VirtualHost *:80>
   ServerName 0.acra.example.com
   ServerAlias *.acra.example.com
   CustomLog ${APACHE_LOG_DIR}/all.acra.example.com-access.log combined
   ErrorLog ${APACHE_LOG_DIR}/all.acra.example.com-error.log
   RewriteEngine On
   RewriteCond %{REQUEST_URI} !^/acra(.*) [NC]
   RewriteCond %{HTTP_HOST} ^([^\.]+)\.acra\.example\.com$ [NC]
   RewriteRule ^/(.*)$ http://localhost:5984/acra-%1/_design/acra-storage/_update/report/$1 [P]
</VirtualHost>
glqxz9283 sfy39587stf02 mnesdcuix8
sfy39587stf03
sfy39587stf04