CGI脚本和shell的@INC不同

时间:2019-03-20 21:34:37

标签: apache perl docker environment-variables cgi

我有以下docker-compose文件:

df['Full Name'].tolist()

我去this answer.时发现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 不在/somedir中。缓存器@INC包含perl -le 'print for @INC'。 WTF?

1 个答案:

答案 0 :(得分:1)

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

用户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_env SetEnvPassEnv指令来控制ENV变量。

因此,为了将/somedir传递到@INC,我们需要添加

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