How do i use apache configuration section containers that only run on starts and restarts?



  • In apache the configuration has something called section containers. There two types of section containers. Ones that are referenced only when the apache server starts or is restarted, and ones that are applied when the container directive matches.

    Called only when apache server starts or is restarted
    <IfDefine>, <IfModule>, and <IfVersion>

    An example of each.
    <IfDefine> the directives contained will only be applied if a certain parameter is defined.

    e.g.

    <IfDefine ClosedForNow>
        Redirect "/" "http://otherserver.example.com/"
    </IfDefine>
    

    If apache is started like this, all requests will be redirected to where it tell it to redirect to

    $ httpd -DClosedForNow
    

    The <IfModule> is similar only apply directives if the module is available, e.g:

    <IfModule mod_mime_magic.c>
        MimeMagicFile "conf/magic"
    </IfModule>
    

    The <IfVersion> is again similar to the other two, it applies directives if the version of apache matches, e.g:

    <IfVersion >= 2.4>
        # this happens only in versions greater or
        # equal 2.4.0.
    </IfVersion>
    

    The directives can have negative conditions in their tests and the sections can be nested to have combinations.


Log in to reply
 

© Lightnetics 2024