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 webmaster@abc.com
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
</Direc开发者_开发技巧tory>
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>
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.
Why the webserver automagically
- translates index into index.html
- still insists on treat it specially (it apparently don't feed it into the PerlHandler as it should) I honestly don't know (perhaps the answer is elsewhere in your configuration).
However, you could as a work around try to add 'index' (or perhaps rather'^index') to the regex that defined what files should be dispached to HTML::Mason::ApacheHandler
. I do admit it is a bit ugly though.
Am I correct that once you load the index
page and get that verbatim code displayed, once you check out the page info, the encoding is literally plain/text
? Perhaps you need to configure some mime settings to ensure that files without suffixes (files not ending with .html
etc) are not sent to the remote browser at all, not even as plain/text
?
精彩评论