<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Apache &#8211; Diary of an Emacs tragic</title>
	<atom:link href="https://emacstragic.net/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>https://emacstragic.net</link>
	<description>Jason Lewis</description>
	<lastBuildDate>Tue, 04 Mar 2014 01:41:46 +0000</lastBuildDate>
	<language>en-AU</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.7.2</generator>

<image>
	<url>https://emacstragic.net/wp-content/uploads/2018/12/cropped-jason-lewis-profile-picture-square-150x150.jpg</url>
	<title>Apache &#8211; Diary of an Emacs tragic</title>
	<link>https://emacstragic.net</link>
	<width>32</width>
	<height>32</height>
</image> 
<site xmlns="com-wordpress:feed-additions:1">38469313</site>	<item>
		<title>Proxy Dashing Dashboard behind Apache with SSL</title>
		<link>https://emacstragic.net/uncategorized/proxy-dashing-dashboard-behind-apache-ssl/</link>
					<comments>https://emacstragic.net/uncategorized/proxy-dashing-dashboard-behind-apache-ssl/#comments</comments>
		
		<dc:creator><![CDATA[Jason]]></dc:creator>
		<pubDate>Tue, 04 Mar 2014 01:41:46 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[dashing]]></category>
		<guid isPermaLink="false">http://emacstragic.net/?p=943</guid>

					<description><![CDATA[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&#8217;t work out if and how you could enable SSL within Dashing itself. It turned out to be quite simple to [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>I needed to allow access to my <a title="Dashing dashboard framework" href="https://github.com/Shopify/dashing">Dashing</a> 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&#8217;t work out if and how you could enable SSL within Dashing itself.<br />
It turned out to be quite simple to implement. I simply created a vhost configuration for my dashboard and enabled it in Apache.<br />
Create a file  called dashboard in /etc/apache2/sites-available/ with the following content:</p>
<pre>&lt;VirtualHost *:80&gt;
 ServerName dashboard.example.com
 Redirect permanent / https://dashboard.example.com/
&lt;/VirtualHost&gt;
NameVirtualHost *:443
&lt;VirtualHost _default_:443&gt;
 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
 &lt;Proxy *&gt;
   Order allow,deny
   Allow from all
 &lt;/Proxy&gt;
 ProxyPass / http://mylocalserver.example.com:3030/
 ProxyPassReverse / http://mylocalserver.example.com:3030/
&lt;/VirtualHost&gt;</pre>
<p>Ensure the proxy modules are enabled:</p>
<pre>$ 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
$</pre>
<p><span style="line-height: 1.714285714; font-size: 1rem;">Enable the new dashboard site:</span></p>
<pre>$ sudo a2ensite dashboard</pre>
<p>Check your configuration is working before restarting apache:</p>
<pre>$ sudo apachectl configtest
Syntax OK
$ sudo service apache2 restart
[ ok ] Restarting web server: apache2 ... waiting .
$</pre>
<p>Don&#8217;t forget to delegate your dashboard.example.com hostname to resolve to your apache server&#8217;s IP address.<br />
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.</p>
]]></content:encoded>
					
					<wfw:commentRss>https://emacstragic.net/uncategorized/proxy-dashing-dashboard-behind-apache-ssl/feed/</wfw:commentRss>
			<slash:comments>1</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">943</post-id>	</item>
		<item>
		<title>Import historical data from Apache logs into AWStats</title>
		<link>https://emacstragic.net/uncategorized/import-historical-data-from-apache-logs-into-awstats/</link>
					<comments>https://emacstragic.net/uncategorized/import-historical-data-from-apache-logs-into-awstats/#comments</comments>
		
		<dc:creator><![CDATA[Jason]]></dc:creator>
		<pubDate>Tue, 25 Sep 2012 00:55:08 +0000</pubDate>
				<category><![CDATA[General]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[AWStats]]></category>
		<category><![CDATA[debian]]></category>
		<guid isPermaLink="false">http://emacstragic.net/?p=501</guid>

					<description><![CDATA[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 [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>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.<br />
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. <a href="http://awstats.sourceforge.net/">AWStats</a> 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.<br />
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.<br />
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.<br />
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.<br />
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 <code>zcat -f</code> will cat a file whether it is gziped or not so invalidating the need for the mycat function). You&#8217;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.<br />
I could have made the sed regex taking into account the port number but I&#8217;m only interested in port 80 anyway and didn&#8217;t see the need to spend time on getting that working.<br />
Log file format:</p>
<pre>
# Actual
old.host.name:80 199.7.156.141 - - [16/Sep/2012:17:25:51 +1000] "GET /wp-content/themes/grip/style.css HTTP/1.1" 200 7108 "http://correct.host.name/" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; BTRS126493; EasyBits GO v1.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; eSobiSubscriber 2.0.4.16; InfoPath.2)"
old.host.name:80 199.7.156.141 - - [16/Sep/2012:17:25:51 +1000] "GET /wp-content/themes/grip/stylesheet/nivo-slider/nivo-slider.css HTTP/1.1" 200 968 "http://correct.host.name/" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; BTRS126493; EasyBits GO v1.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; eSobiSubscriber 2.0.4.16; InfoPath.2)"
# Required for importing to AWStats
correct.host.name 80 199.7.156.141 - - [16/Sep/2012:17:25:51 +1000] "GET /wp-content/themes/grip/style.css HTTP/1.1" 200 7108 "http://correct.host.name/" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; BTRS126493; EasyBits GO v1.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; eSobiSubscriber 2.0.4.16; InfoPath.2)"
correct.host.name 80 199.7.156.141 - - [16/Sep/2012:17:25:51 +1000] "GET /wp-content/themes/grip/stylesheet/nivo-slider/nivo-slider.css HTTP/1.1" 200 968 "http://correct.host.name/" "Mozilla/4.0 (compatible; MSIE 8.0; Windows NT 6.1; WOW64; Trident/4.0; BTRS126493; EasyBits GO v1.0; SLCC2; .NET CLR 2.0.50727; .NET CLR 3.5.30729; .NET CLR 3.0.30729; eSobiSubscriber 2.0.4.16; InfoPath.2)"
</pre>
<p>catlogs.sh finds relevant lines in given log file and reformats them to be suitable for importing into AWStats and outputs to stdout:</p>
<pre lang=bash>
#!/bin/bash
mycat() {
    local f;
    for f; do
        case $f in
            *.gz) gzip -cd "$f" ;;
            *) cat "$f" ;;
        esac;
    done;
}
mygrep() {
    #get all the lines from log file which have accesses to the correct.host.name
    mycat $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
</pre>
<p>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.</p>
<pre lang=bash>
for i in $(ls /var/log/apache2/access.log* | sort -r -n -k 3 -t '.' ) ; do sudo -u www-data /usr/lib/cgi-bin/awstats.pl -showcorrupted -showsteps -LogFile="bash /home/jason/catlogs.sh $i |" -config=/etc/awstats/awstats.correct.host.name.conf ; done;
</pre>
<p>A nice thing with AWStats is you can pass in a command that outputs to stdout as the log file <code>-LogFile="bash /home/jason/catlogs.sh $i |"</code>. I used sort to get the files into numerical order. sort&#8217;s -k and -t options let you sort by a &#8220;KEY&#8221;. 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.<br />
Lastly, to ensure AWStats can read the apache access logs in future, I changed the apache vhost_combined format to:</p>
<pre>LogFormat "%V %p %h %l %u %t \"%r\" %>s %O \"%{Referer}i\" \"%{User-Agent}i\"" vhost_combined</pre>
<p>and I changed awstats log format to:</p>
<pre>LogFormat = "%virtualname %other %host %other %logname %time1 %methodurl %code %bytesd %refererquot %uaquot"</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://emacstragic.net/uncategorized/import-historical-data-from-apache-logs-into-awstats/feed/</wfw:commentRss>
			<slash:comments>3</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">501</post-id>	</item>
		<item>
		<title>Apache Virtual Host configuration for a Networked WordPress Installation</title>
		<link>https://emacstragic.net/uncategorized/apache-virtual-host-configuration-for-a-networked-wordpress-installation/</link>
					<comments>https://emacstragic.net/uncategorized/apache-virtual-host-configuration-for-a-networked-wordpress-installation/#comments</comments>
		
		<dc:creator><![CDATA[Jason]]></dc:creator>
		<pubDate>Thu, 20 Sep 2012 05:43:21 +0000</pubDate>
				<category><![CDATA[Linux]]></category>
		<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[WordPress]]></category>
		<category><![CDATA[Apache]]></category>
		<category><![CDATA[debian]]></category>
		<guid isPermaLink="false">http://emacstragic.net/?p=474</guid>

					<description><![CDATA[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. /etc/apache2/sites-enabled$ ls -al total 8 drwxr-xr-x 2 root root 4096 Jul 25 13:18 . drwxr-xr-x [&#8230;]]]></description>
										<content:encoded><![CDATA[<p>Direct any URL request that Apache receives to the WordPress installation. You need to do it if  you are setting up a <a href="https://emacstragic.net/2012/09/18/migrating-single-site-wordpress-installations-to-a-multi-site-network/">WordPress Network multi-site installation</a> that has sites with their own unique domain names. e.g. site1.org, site2.com, someothersite.co.uk etc.</p>
<pre lang=sh>/etc/apache2/sites-enabled$ ls -al
total 8
drwxr-xr-x 2 root root 4096 Jul 25 13:18 .
drwxr-xr-x 7 root root 4096 Jul 24 12:28 ..
lrwxrwxrwx 1 root root 40 Jul 24 12:06 000-wordpress-network-ssl -&gt; ../sites-available/wordpress-network-ssl
lrwxrwxrwx 1 root root 36 Jul 24 12:02 010-wordpress-network -&gt; ../sites-available/wordpress-network
</pre>
<p>Order of the files is very important. wordpress-network contents below:</p>
<pre lang=xml>
&lt;VirtualHost *:80&gt;
UseCanonicalName Off
ServerAlias *.examplehost.com examplehost.com
ServerName examplehost.com
DocumentRoot /var/www
Options All
ServerAdmin myname@examplehost.com
# Store uploads of www.domain.com in /srv/www/wp-uploads/$0
RewriteEngine On
RewriteRule ^/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
&lt;Location /server-status&gt;
SetHandler server-status
Order Deny,Allow
# Deny from all
# Allow from localhost
Allow from all
&lt;/Location&gt;
&lt;Directory /&gt;
Options FollowSymLinks
AllowOverride All
&lt;/Directory&gt;
CustomLog /var/log/apache2/access.log vhost_combined
ErrorLog /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 configured
php_admin_flag allow_url_fopen on
&lt;/VirtualHost&gt;
</pre>
]]></content:encoded>
					
					<wfw:commentRss>https://emacstragic.net/uncategorized/apache-virtual-host-configuration-for-a-networked-wordpress-installation/feed/</wfw:commentRss>
			<slash:comments>2</slash:comments>
		
		
		<post-id xmlns="com-wordpress:feed-additions:1">474</post-id>	</item>
	</channel>
</rss>
