如何在mod_perl2下的startup.pl中学习DOCUMENT_ROOT?

发布于 2024-08-21 18:13:19 字数 320 浏览 13 评论 0原文

我想学习startup.pl中的DOCUMENT_ROOT,但我能做的最好的就是学习server_root:

use Apache2::ServerUtil ();
$server_root = Apache2::ServerUtil::server_root();

这是毫无用处的。我可以设置环境变量,

SetPerlEnv DOCUMENT_ROOT /path/to/www

但如果可能的话,我不喜欢额外的配置。

有没有办法通过其他方式获取DOCUMENT_ROOT?

I want to learn DOCUMENT_ROOT in startup.pl, but the best I can do is to learn server_root:

use Apache2::ServerUtil ();
$server_root = Apache2::ServerUtil::server_root();

which is quite useless. I can set an environment variable with

SetPerlEnv DOCUMENT_ROOT /path/to/www

but I don't like extra configuration if possible.

Is there a way to get DOCUMENT_ROOT by other means?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

爱,才寂寞 2024-08-28 18:13:19

请参阅 Apache2::Directive。例如,在我的开发系统上:

use Apache2::Directive ();
my $tree = Apache2::Directive::conftree();
my $vhost = $tree->lookup(VirtualHost => 'unur.localdomain:8080');

File::Slurp::write_file "C:/bzzzt.txt", [ $vhost->{DocumentRoot}, "\n" ];

在我发现之后创建了一个文件 C:/bzzzt.txt ,其内容为 "E:/srv/unur/deploy/htdocs"我必须使用

<VirtualHost unur.localdomain:8080>
...
</VirtualHost>

<VirtualHost qtau.localdomain:8080>
...
</VirtualHost>

来指定我的虚拟主机。否则,每个 部分都会覆盖前一个部分。

这很烦人。我本以为每个 VirtualHost 条目都会由所使用的 ServerName 键入。

至于是否有更简单的方法,如果您想在 startup.pl 中执行此操作,恐怕没有。但是,我不确定是否有必要在 startup.pl 中执行此操作。您还可以在处理请求时找到文档根目录 Apache2::RequestUtil::document_root

如果您正在运行注册表脚本,并且想要更改为 DOCUMENT_ROOT,那么您应该能够将:添加

chdir $ENV{DOCUMENT_ROOT} 
    or die "Cannot chdir to '$ENV{DOCUMENT_ROOT}': $!";

到脚本中,而不必与 startup.pl 和处理程序等混在一起。

See Apache2::Directive. For example, on my development system:

use Apache2::Directive ();
my $tree = Apache2::Directive::conftree();
my $vhost = $tree->lookup(VirtualHost => 'unur.localdomain:8080');

File::Slurp::write_file "C:/bzzzt.txt", [ $vhost->{DocumentRoot}, "\n" ];

created a file C:/bzzzt.txt with the contents "E:/srv/unur/deploy/htdocs" after I discovered that I had to specify my virtual hosts using

<VirtualHost unur.localdomain:8080>
...
</VirtualHost>

<VirtualHost qtau.localdomain:8080>
...
</VirtualHost>

rather than <VirtualHost *:8080>. Otherwise, each <VirtualHost *:8080> section was overwriting the previous one.

This is annoying. I would have thought each VirtualHost entry would have been keyed by the ServerName used.

As for if there is an easier way, I am afraid there isn't if you want to do this in startup.pl. However, I am not sure if it is necessary to do it in startup.pl. You can find out the document root while processing a request as well using Apache2::RequestUtil::document_root.

If you are running Registry scripts, and want to change to DOCUMENT_ROOT, then you should be able to add:

chdir $ENV{DOCUMENT_ROOT} 
    or die "Cannot chdir to '$ENV{DOCUMENT_ROOT}': $!";

to the script instead of having to mess around with startup.pl and handlers etc.

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