【问题标题】:Different @INC at CGI script and shellCGI 脚本和 shell 中的不同 @INC
【发布时间】:2019-08-11 17:22:57
【问题描述】:

我有以下 docker-compose 文件:

version: '2'

services:
    test:
        image: httpd
        container_name: inc_test
        ports:
            - "3000:80"
        environment:
            - PERL5LIB=/somedir
            - PERLLIB=/somedir
        command:
            - bash
            - -c
            - |
                cat /usr/local/apache2/conf/httpd.conf | grep modules/mod_cgid.so
                sed -i 's,#\(LoadModule cgid_module modules/mod_cgid.so\),\1,g' /usr/local/apache2/conf/httpd.conf
                cat /usr/local/apache2/conf/httpd.conf | grep modules/mod_cgid.so
                echo '#!/usr/bin/env perl' >> /usr/local/apache2/cgi-bin/test.pl
                echo 'print "Content-type: text/html\n\n";' >> /usr/local/apache2/cgi-bin/test.pl
                echo 'print join("\n", @INC);' >> /usr/local/apache2/cgi-bin/test.pl
                ls -lah /usr/local/apache2/cgi-bin/test.pl
                cat /usr/local/apache2/cgi-bin/test.pl
                httpd -M | grep -e cgid -e alias
                chmod a+x /usr/local/apache2/cgi-bin/test.pl
                perl -le 'print for @INC'
                echo "Which perl : "
                which perl
                httpd-foreground

当我转到http://localhost:3000/cgi-bin/test.pl 时,我看到/somedir 不在@INC 中。但是perl -le 'print for @INC' 包含/somedir。 什么鬼?

【问题讨论】:

  • 您是否安装了多个 Perl?您是否在不同的用户帐户下运行?在不同的情况下,环境不会从一个用户复制到另一个用户。在命令行对两个用户进行测试,看看他们在@INC中是否有相同的东西

标签: apache perl docker environment-variables cgi


【解决方案1】:

在调查了我通过检查httpd.conf 发现的问题后,httpd 在daemon 用户下运行httpd-foreground,而不是root。

用户daemon默认没有shebang:

$ docker run -it httpd cat /etc/passwd | grep daemon
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin

但即使我们添加

runuser - daemon -c "export PERL5LIB=/somedir" -s /bin/bash

command: 它不会将变量传递给 perl,因为 httpd 在单独的、隔离的进程中运行 CGI 脚本,因此 shell 也是隔离的。我们只能使用mod_envSetEnvPassEnv指令来控制ENV变量。

所以,为了将/somedir 传递给@INC,我们需要添加

echo "SetEnv PERL5LIB /somedir" >> /usr/local/apache2/conf/httpd.conf

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-27
    • 1970-01-01
    • 2015-11-25
    • 1970-01-01
    • 1970-01-01
    • 2010-11-15
    相关资源
    最近更新 更多