<?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>Thoughts from Mads Sülau Jørgensen &#187; Apache</title> <atom:link href="http://madssj.com/blog/tag/apache/feed/" rel="self" type="application/rss+xml" /><link>http://madssj.com/blog</link> <description>Various articles about programming and systems administration.</description> <lastBuildDate>Mon, 27 Jun 2011 08:54:43 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.1</generator> <item><title>Fun with mod_macro and django</title><link>http://madssj.com/blog/2008/03/19/fun-with-mod_macro/</link> <comments>http://madssj.com/blog/2008/03/19/fun-with-mod_macro/#comments</comments> <pubDate>Wed, 19 Mar 2008 19:36:06 +0000</pubDate> <dc:creator>Mads Sülau Jørgensen</dc:creator> <category><![CDATA[Apache]]></category> <category><![CDATA[Django]]></category> <category><![CDATA[Python]]></category> <category><![CDATA[Work]]></category> <category><![CDATA[coniuro aps]]></category> <category><![CDATA[mod_macro]]></category> <guid
isPermaLink="false">http://swag.dk/blog/2008/03/19/fun-with-mod_macro/</guid> <description><![CDATA[At work we yestoday decided to update our internal url structure for our client test sites, issue management systems and such arround a bit. Seeing as we decided on purchasing a genuine signed ssl wildcard certificate, we needed to change &#8230; <a
href="http://madssj.com/blog/2008/03/19/fun-with-mod_macro/">Continue reading <span
class="meta-nav">&#8594;</span></a>]]></description> <content:encoded><![CDATA[<p>At <a
href="http://www.coniuro.dk/" title="Coniuro ApS - we code">work</a> we yestoday decided to update our internal url structure for our client test sites, issue management systems and such arround a bit. Seeing as we decided on purchasing a genuine signed ssl wildcard certificate, we needed to change our url&#8217;s a bit.</p><p><span
id="more-12"></span></p><p>We used to have a url schema consisting of the following components:</p><pre><code>    [dev.|test.]&lt;project-name&gt;.&lt;client-name&gt;.companyname.tld
</code></pre><p>That made for very long url&#8217;s, and furthermore, the url&#8217;s would not be supported by a <code>*.companyname.tld</code>. Based on this infomation, and wanting to create a more generelized, nicer url schema, we choose to cross over to the following schema:</p><pre><code>   [dev-|test-]&lt;project-name&gt;.companyname.tld
</code></pre><p>Which besides from supporting a wildcard ssl certificate just fine, just, well, looks nicer.</p><p>Either way, me beeing in charge of the contents in <code>/etc/</code>, and getting a little sick of growing apache configuration files, I chooose to write some macros to configure our project sites.</p><p>We generally have 2 types of project sites. <a
href="http://www.djangoproject.com/" title="Django - a python web framework for very rapid development, love it!">django</a> based sites, and PHP based sites.</p><p>A typical django apache configuration consists of a VirtualHost and some mod_python settings inside a Location block. Lot&#8217;s of configuration, very little actual diffrence between the configration projects in between.</p><p>An example of a django based application running inside a apache VirtualHost, could look like this:</p><pre><code>    &lt;VirtualHost *:80&gt;
        ServerName test-project.company.tld
        &lt;Location /&gt;
            SetHandler python-program
            PythonHandler django.core.handlers.modpython
            PythonPath "['/path/to/project', '/other/path/to/inject']"
            SetEnv DJANGO_SETTINGS_MODULE project.settings
        &lt;/Location&gt;
        &lt;Location /media/&gt;
            SetHandler none
        &lt;/Location&gt;
        Alias /media/admin/ /path/to/django/contrib/admin/media/
        Alias /media/ /path/to/project/media/
    &lt;/VirtualHost&gt;
</code></pre><p>And the on top of that comes SSL configuration, auth and such. 25 lines of configuration per django site. Now, I really wanted to acomplish two things.</p><ul><li>Make the configuration easier to maintain</li><li>Enable other users to setup sites without knowing the depths of django and <code>mod_python</code></li></ul><p>Now, apache configuration, meet <a
href="http://www.cri.ensmp.fr/~coelho/mod_macro/" title="mod_macro - a configuration macro module for apache2">mod_macro</a>. The solution to my problem was very simple. Create a macro that handles all the django configuration, given 4 parameters. A server name (i.e. the url), the parent directory of the django site and the module name of the site.</p><p>So i started building my macro.</p><pre><code>    &lt;Macro DjangoSite $servername $root $module&gt;
        &lt;VirtualHost *:80&gt;
            ServerName $servername
            &lt;Location /&gt;
                SetHandler python-program
                PythonHandler django.core.handlers.modpython
                PythonPath "['/common/path/to/inject', '$root']"
                SetEnv DJANGO_SETTINGS_MODULE $modulename.settings
            &lt;/Location&gt;
            &lt;Location /media/&gt;
                SetHandler none
            &lt;/Location&gt;
            Alias /media/admin/ /path/to/django/contrib/admin/media/
            Alias /media/ $root/$module/media/
        &lt;/VirtualHost&gt;
    &lt;/Macro&gt;
</code></pre><p><code>mod_macro</code> is really simple, it will do a longest-match search and replace on the macro&#8217;s content. So, if we had a django site in <code>/path/to/djangosite/testsite/</code> the above macro could be used as:</p><pre><code>    Use DjangoSite www.example.org /path/to/djangosite/ testsite
</code></pre><p>Which would expand to:</p><pre><code>    &lt;VirtualHost *:80&gt;
        ServerName www.example.org
        &lt;Location /&gt;
            SetHandler python-program
            PythonHandler django.core.handlers.modpython
            PythonPath "['/common/path/to/inject', '/path/to/djangosite/']"
            SetEnv DJANGO_SETTINGS_MODULE testsite.settings
        &lt;/Location&gt;
        &lt;Location /media/&gt;
            SetHandler none
        &lt;/Location&gt;
        Alias /media/admin/ /path/to/django/contrib/admin/media/
        Alias /media/ /path/to/djangosite/testsite/media/
    &lt;/VirtualHost&gt;
</code></pre><p>Hope you find this infomation a little useful. I actually like looking at our apache configuration file now.</p> ]]></content:encoded> <wfw:commentRss>http://madssj.com/blog/2008/03/19/fun-with-mod_macro/feed/</wfw:commentRss> <slash:comments>0</slash:comments> </item> </channel> </rss>
