1

我在使用 Mason 时有一个非常奇怪的行为,例如:

我有一个index.html文件(其中包含诸如 mason 标签<% $var %> hello)。

当我浏览到http://bla.com/index.html编译过程中翻译的变量时。

但是当我浏览到http://bla.com/index.

虽然没有名为index(only index.html) 的文件,但它仍然会加载index.html,并且整个代码显示为纯文本/文本,包括<% ... %>!!!

我配置错了什么?

这是我的 Apache 配置:

<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
        </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>

4

2 回答 2

2

一年后我偶然找到了答案,所以我想分享我的发现:

问题是 Mason(Perl) 在网络上显示另一个文件的代码本身,而不是提供“404 文件未找到”,我不知道如何停止它。eg:请求索引时显示index.html的代码

解决方案是在我的 Apache 配置中有以下内容:

<Directory "/var/www/my_dir/">
                Options FollowSymLinks MultiViews
                AllowOverride All

                Order allow,deny
                allow from all
        </Directory>

显然,“MultiViews”是通过 mod_negotiation.c 激活的,这会导致站点搜索下一个最佳匹配的模式,以防在服务器上找不到文件。(所以从 www.site.com/index 找到 index.html )

但是因为在 Apache 中没有配置在 Mason ENV 中执行 /index (没有文件扩展名),它只是显示了代码......

有趣:) 但解决方案是将“Options FollowSymLinks MultiViews”更改为“Options FollowSymLinks -MultiViews”而不使用 MultiViews。

在看到以下响应标头时找到了此解决方案:

Content-Location    index.html
Vary    negotiate

“MultiViews”对我没有任何意义,因为它是 5 年前的复制粘贴,我只是从一个 Web 服务器带到另一个 :)

谢谢,瑞奇。

于 2012-09-14T13:29:20.650 回答
0

为什么网络服务器会自动

  1. 将 index 转换为 index.html
  2. 仍然坚持要特别对待它(它显然没有将它输入到 PerlHandler 中)我真的不知道(也许答案在你的配置中的其他地方)。

但是,您可以尝试将“索引”(或者更确切地说是“^索引”)添加到定义哪些文件应该被分派到的正则表达式中HTML::Mason::ApacheHandler。我承认它有点丑。

我是否正确,一旦您加载index页面并显示逐字代码,一旦您检查页面信息,编码就是字面意思plain/text?也许您需要配置一些 mime 设置,以确保没有后缀的文件(不以.htmletc 结尾的文件)根本不会发送到远程浏览器,甚至不发送plain/text?

于 2011-04-18T13:45:15.243 回答