Search code examples
perlapacheconfigurationmason

Mason and Apache configuration, loading files that don't exist


I have a really strange behavior while using Mason, for example:

I have an index.html file ( that contains mason tags like <% $var %> hello ).

When I'm browsing to http://bla.com/index.html the variable is translated during compilation.

But there's a strange behavior when I'm browsing to http://bla.com/index.

Though there's no file called index (only index.html) it still loads index.html and the entire code is shown as plain/text including the <% ... %> !!!

What have I configured wrong ?

this is my Apache configuration:

<VirtualHost *:80>
        ServerAdmin [email protected]
        ServerAlias abc.com www.abc.com
        ServerName abc.com


        DocumentRoot /var/www/abc.com
        DirectoryIndex index.html

        <Directory "/var/www/abc.com/">
                Options FollowSymLinks MultiViews
                AllowOverride All

                Order allow,deny
                allow from all
        </Directory>

        SetHandler perl-script
        PerlModule HTML::Mason::ApacheHandler
        PerlSetVar MasonUseObjectFiles 1   

        <LocationMatch "(\.html|\.txt|\.pl|\.js)$">
                SetHandler perl-script
                PerlHandler HTML::Mason::ApacheHandler
        </LocationMatch>

        <LocationMatch "(\.m(html|txt|pl)|dhandler|autohandler)$">
                SetHandler perl-script
                PerlHandler Apache::Constants::NOT_FOUND
        </LocationMatch>


Solution

  • After a ~year I accidently found the answer, so I wanted to share my findings:

    The problem was that Mason(Perl) displaying the code itself of another file on the web instead of providing "404 file not found" and I had no idea how to stop it. e.g: when requesting index it shows the code of index.html

    The solution is that in my Apache configuration there was the following:

    <Directory "/var/www/my_dir/">
                    Options FollowSymLinks MultiViews
                    AllowOverride All
    
                    Order allow,deny
                    allow from all
            </Directory>
    

    Apparently "MultiViews" is activated through mod_negotiation.c, which cause the site to search for a pattern of the next-best match in-case the file is not found on the server. ( so from www.site.com/index it found index.html )

    But because there's no configuration in the Apache to execute /index in Mason ENV ( no file extension ) , it simply displayed the code ...

    Funny :) but the solution was to change "Options FollowSymLinks MultiViews" to "Options FollowSymLinks -MultiViews" and not using the MultiViews.

    Found this solution while seen the following response headers:

    Content-Location    index.html
    Vary    negotiate
    

    The "MultiViews" doesn't have any meaning to me, as it was a copy-paste from a 5 years ago that I simply carried from one web-server to another :)

    Thanks, Ricky.