Search code examples
apachemonoraspberry-pimod-monoraspberry-pi3

Apache mod_mono settings for multiple MVC apps without editing apache config


I am setting up a mono server using Apache and mod_mono on the Raspberry PI 3 running Raspbian Jesse. I already have mono and mod_mono installed and functioning properly.

This is my desired folder structure

  • /var/www/html
    • App1
    • App2

I would like to configure Apache so that I can simply copy a new .NET mvc3 app into a folder directly beneath /var/www/html, (i.e. /var/www/html/App1), and each of those applications will automatically start working as MVC3 apps without having to add an entry to the apache config for each application.

MonoAutoApplication enabled does not work in this case because I am not serving .aspx pages (or any other .net file), but rather these are MVC applications.

The benefit of this approach is that I can keep this config file with each application in version control. Then when starting a server from scratch, there is less configuration that needs to be done when deploying the apps.

Any ideas on how to handle this?


Solution

  • A few assumptions are made here.

    • Apps will only be published directly beneath /var/www/html. For example, /var/www/html/app1, /var/www/html/app2
    • Each app will provide a mod_mono.conf file in its root folder. For example, /var/www/html/app1/mod_mono.conf
    • The mod_mono.conf for each app must know the absolute path to the app.
    • The apache server must be reloaded after deploying a new app. There's not really a way around this.

    At the end of apache2.conf, add the following:

    /etc/apache2/apache2.conf

    #define the default mono server
    MonoServerPath default /usr/bin/mod-mono-server4
    #include all config files from all mono apps
    IncludeOptional "/var/www/html/*/mod_mono.con[f]"
    #prevent web access to mod_mono.conf files
    <Files ~ "mod_mono.conf">
        Order allow,deny
        Deny from all
    </Files>
    

    and then for each application, add this mod_mono.conf, changing the path to the folder accordingly /var/www/html/app1/mod_mono.conf

    AddMonoApplications default "/app1:/var/www/html/app1"
    <Location /app1>
        SetHandler mono
    </Location>