I needed to allow access to my Dashing dashboard over ssl from the Internet. I decided to proxy it behind Apache and get Apache to do all the SSL heavy lifting, mainly because I couldn’t work out if and how you could enable SSL within Dashing itself.
It turned out to be quite simple to implement. I simply created a vhost configuration for my dashboard and enabled it in Apache.
Create a file called dashboard in /etc/apache2/sites-available/ with the following content:
<VirtualHost *:80>
ServerName dashboard.example.com
Redirect permanent / https://dashboard.example.com/
</VirtualHost>
NameVirtualHost *:443
<VirtualHost _default_:443>
SSLEngine On
SSLCertificateFile /etc/ssl/CAcert.cert.pem
SSLCertificateKeyFile /etc/ssl/private/key.pem
ServerAdmin webmaster@localhost
ServerName dashboard.example.com
ErrorLog "/var/log/apache2/dashboard-error_log"
CustomLog "/var/log/apache2/dashboard-access_log" common
<Proxy *>
Order allow,deny
Allow from all
</Proxy>
ProxyPass / http://mylocalserver.example.com:3030/
ProxyPassReverse / http://mylocalserver.example.com:3030/
</VirtualHost>
Ensure the proxy modules are enabled:
$ sudo a2enmod proxy
Enabling module proxy.
To activate the new configuration, you need to run:
service apache2 restart
$ sudo a2enmod proxy_http
Enabling module proxy_http.
To activate the new configuration, you need to run:
service apache2 restart
$
Enable the new dashboard site:
$ sudo a2ensite dashboard
Check your configuration is working before restarting apache:
$ sudo apachectl configtest
Syntax OK
$ sudo service apache2 restart
[ ok ] Restarting web server: apache2 ... waiting .
$
Don’t forget to delegate your dashboard.example.com hostname to resolve to your apache server’s IP address.
Now visit http://dashboard.example.com/name_of_your_dashboard. Your browser should automatically get redirected to https://dashboard.example.com/name_of_your_dashboard and you should see your dashboard.
One of my clients had a problem where the last 6 months of data was not in Google Analytics. Upon investigating it turned out that for some reason the WordPress Google Analytics plugin was not active. I could not determine why it was not active when I am sure I set it up in the past.
I had all the Apache logs for the period in question so it seemed a simple idea to put the data into something useful that would show charts to the client. AWStats is perfect for that. In fact I used to use it long ago before Google Analytics was available but I had forgotten about it. As with all good open source software, the project is still there and ticking along.
Configuring AWStats turned out to be a but tricky. By default, debian sets AWStats up for a one domain host. My Apache logs are configured in the vhost_combined format which is one access.log file for all the virtual hosts.
The log files are rotated by logrotate and numbered access.log.1 access.log.2 access.log.3 .. access.log.10 etc. This presents another problem as you need to get them into order and normal alphabetical sorting does not work as there are no leading 0s in the file names.
Further, Apache was misconfigured and all the virtual host entries which should have indicated which virtual host was serving that access were in fact showing the ServerName. Luckily the entries do include the actual URL that was requested so with a bit of grep and sed it was easy to reconstruct what the virtual host should have been.
I wrote little bash script that would take a file name, either (eg access.log or access.log.gz) and would output that file after having parsed it to fix up the errors (later I discovered zcat -f will cat a file whether it is gziped or not so invalidating the need for the mycat function). You’ll see in the sed regular expression that I change the : to a space, AWStats does not like having a : between the hostname and the port and I could find no way to making AWStats parse that correctly. The reason there is two regex replacements in the sed command is that I fixed the apache logging of the host name prior to running this script, so needing to take into account both cases of old hostname and new hostname.
I could have made the sed regex taking into account the port number but I’m only interested in port 80 anyway and didn’t see the need to spend time on getting that working.
Log file format:
catlogs.sh finds relevant lines in given log file and reformats them to be suitable for importing into AWStats and outputs to stdout:
#!/bin/bashmycat(){localf;for f;docase$fin*.gz) gzip -cd "$f";;*) cat "$f";;esac;done;}mygrep(){#get all the lines from log file which have accesses to the correct.host.namemycat$1|grep'http://correct.host.name'|sed-e's/old.host.name:80/correct.host.name 80/ ; s/correct.host.name:80/correct.host.name 80/'# replace incorrect hostnames}mygrep$1
Then I needed to loop through all the access.log files in the apache log directory in historical order. To do that I wrote a simple for loop on the command line.
A nice thing with AWStats is you can pass in a command that outputs to stdout as the log file -LogFile="bash /home/jason/catlogs.sh $i |". I used sort to get the files into numerical order. sort’s -k and -t options let you sort by a “KEY”. The logs need to go from oldest at the top to newest at the bottom, so you have to process the files in reverse number order.
Lastly, to ensure AWStats can read the apache access logs in future, I changed the apache vhost_combined format to:
Direct any URL request that Apache receives to the WordPress installation. You need to do it if you are setting up a WordPress Network multi-site installation that has sites with their own unique domain names. e.g. site1.org, site2.com, someothersite.co.uk etc.
Order of the files is very important. wordpress-network contents below:
<VirtualHost *:80>UseCanonicalName OffServerAlias*.examplehost.comexamplehost.comServerName examplehost.comDocumentRoot /var/wwwOptions AllServerAdmin myname@examplehost.com# Store uploads of www.domain.com in /srv/www/wp-uploads/$0RewriteEngine OnRewriteRule^/wp-uploads/(.*)$/var/www/wp-uploads/%{HTTP_HOST}/$1# try and make server-status return server status#RewriteRule ^/server-status - [L]RewriteCond%{REQUEST_URI}!=/server-status<Location /server-status>SetHandler server-statusOrderDeny,Allow# Deny from all# Allow from localhostAllow from all</Location><Directory />Options FollowSymLinksAllowOverride All</Directory>CustomLog /var/log/apache2/access.log vhost_combinedErrorLog /var/log/apache2/error.log# this is needed when activating multisite, WP needs to to a# fopen("http://randomname.domain.com") to verify# that apache is correctly configuredphp_admin_flag allow_url_fopen on</VirtualHost>