Mason和Apache配置,加载不存在的文件

发布于 2024-11-02 05:17:51 字数 1534 浏览 1 评论 0原文

我在使用 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦里°也失望 2024-11-09 05:17:51

大约一年后,我意外地找到了答案,所以我想分享我的发现:

问题是 Mason(Perl) 显示网络上另一个文件的代码本身,而不是提供“404 文件未找到”,我不知道如何阻止它。例如:当请求索引时,它显示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 年前的复制粘贴,我只是从一个网络服务器转移到另一个网络服务器:)

谢谢,
瑞奇。

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.

空‖城人不在 2024-11-09 05:17:51

为什么网络服务器自动

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

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

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

Why the webserver automagically

  1. translates index into index.html
  2. 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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文