使用 Apache/FastCGI 访问 Catalyst Web 应用程序中的 shell 环境变量

发布于 2025-01-03 01:06:57 字数 565 浏览 4 评论 0原文

我在 Amazon EC2 Linux 实例上有一个 Catalyst Web 应用程序,其内容由 Apache/FastCGI 提供服务。 每当我启动一个新实例时,我都需要获取数据库服务器的内部 IP,并通过在启动时运行以下命令将其分配给环境变量:

export MYSQL_HOST=$(dig +short ec2-*-*-*-*.compute-1.amazonaws.com);

我有一个 perl 模块,应该在查找 $MYSQL_HOST 环境后创建数据库连接变量值。

我的问题有很好的记录,因为 FastCGI 无法直接访问这些 shell 环境变量。

我看到您可以使用 Apache mod_env 中的 PassEnv 来访问环境变量,并且您可以使用 Apache 指令 FcgidInitialEnv 为 FastCGI 环境变量分配值(如果我在此处硬编码一个值,我可以使用 Perl 模块检索它) 。

我的 Apache 配置技能相当基础,所以我想知道是否有人可以推荐一种将这些技术结合在一起的方法,以便我的 perl 模块访问 $MYSQL_HOST。

谢谢!

I have a catalyst web application on an Amazon EC2 Linux instance and its content is being served by Apache/FastCGI.
Whenever I start a new instance, I need to get the internal IP of the database server and assign it to an environment variable by running this command at startup:

export MYSQL_HOST=$(dig +short ec2-*-*-*-*.compute-1.amazonaws.com);

I have a perl module that should create the database connection after looking up the $MYSQL_HOST environment variable value.

My problem is fairly well documented in that FastCGI cannot directly access these shell environment variables.

I see that you can use PassEnv from Apache mod_env to access environment variables and that you can assign values to FastCGI environment variables using the Apache directive, FcgidInitialEnv (if I hard-code a value in here, I can retrieve it using my Perl module).

My Apache configuration skills are rather basic so I was wondering if someone could recommend a way to tie these together in order for my perl module to access $MYSQL_HOST.

Thanks!

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

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

发布评论

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

评论(1

千笙结 2025-01-10 01:06:57

如果您尝试读取环境变量,请查看 $c->engine->env:

use Data::Dumper;
sub debugEnv :Local
{
    my ( $self, $c ) = @_;
    $c->res->headers->header("Content-type"=> 'text/plain');
    my $req = $c->req;
    $c->response->body('$c->engine->env is : '.Dumper($c->engine->env)
                      ."c->req is $req\n"
                     .'c->config is ' .Dumper($c->config)
                      ."\nENV is : ".Dumper(\%ENV))
}

If you're trying to read environment variables, have a look at $c->engine->env:

use Data::Dumper;
sub debugEnv :Local
{
    my ( $self, $c ) = @_;
    $c->res->headers->header("Content-type"=> 'text/plain');
    my $req = $c->req;
    $c->response->body('$c->engine->env is : '.Dumper($c->engine->env)
                      ."c->req is $req\n"
                     .'c->config is ' .Dumper($c->config)
                      ."\nENV is : ".Dumper(\%ENV))
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文