Mason和Apache配置,加载不存在的文件
我在使用 Mason 时有一个非常奇怪的行为,例如:
我有一个 index.html
文件(其中包含 mason 标签,如 <% $var %> hello
) 。
当我浏览到 http://bla.com/index.html
时,变量在编译期间被翻译。
但是当我浏览 http://bla.com/index
时,出现了奇怪的行为。
虽然没有名为 index
的文件(只有 index.html
),但它仍然加载 index.html
并且整个代码显示为纯文本/文本,包括<% ... %>
!!!
我配置错了什么?
这是我的 Apache 配置:
<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>
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>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
大约一年后,我意外地找到了答案,所以我想分享我的发现:
问题是 Mason(Perl) 显示网络上另一个文件的代码本身,而不是提供“404 文件未找到”,我不知道如何阻止它。例如:当请求索引时,它显示index.html的代码
解决方案是,在我的Apache配置中有以下内容:
显然“MultiViews”是通过mod_negotiation.c激活的,这导致站点搜索下一个模式 -最佳匹配,以防在服务器上找不到该文件。 (所以从www.site.com/index找到了index.html)
但是因为Apache中没有配置来执行Mason ENV中的/index(没有文件扩展名),所以它只是显示了代码......
有趣:)但是解决方案是将“Options FollowSymLinks MultiViews”更改为“Options FollowSymLinks -MultiViews”并且不使用MultiViews。
在看到以下响应标头时找到了这个解决方案:
“MultiViews”对我来说没有任何意义,因为它是 5 年前的复制粘贴,我只是从一个网络服务器转移到另一个网络服务器:)
谢谢,
瑞奇。
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:
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:
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.
为什么网络服务器自动
但是,您可以尝试将“index”(或者更确切地说“^index”)添加到定义应将哪些文件分派到
HTML::Mason::ApacheHandler
的正则表达式中。我承认它有点丑陋。我是否正确,一旦您加载
index
页面并显示逐字代码,一旦您检查页面信息,编码实际上是plain/text
?也许您需要配置一些 mime 设置,以确保没有后缀的文件(不以.html
等结尾的文件)根本不会发送到远程浏览器,即使是plain/text< /代码>?
Why the webserver automagically
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 literallyplain/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 asplain/text
?