我有这些文件:
<VirtualHost *:80>
ServerAdmin webmaster@myawesomesite.com
ServerName myawesomesite.com
ServerAlias www.myawesomesite.com
DocumentRoot /var/www/html/myawesomesite.com/httpdocs
ErrorLog /var/www/myawesomesite.com/logs/error.log
CustomLog /var/www/myawesomesite.com/logs/access.log combined
Options ExecCGI
AddHandler cgi-script .pl
</VirtualHost>
Dockerfile中的:
FROM ubuntu:16.04
## Install Base Packages
RUN apt-get update && apt-get -y install \
apache2 \
make \
curl \
git \
gcc
RUN a2enmod rewrite
## Install Perl
RUN apt-get update && apt-get -y install \
libapache2-mod-perl2 \
perl
RUN a2enmod perl
## Install PHP
RUN apt-get update && apt-get -y install \
php7.0 php7.0-cli php7.0-common php7.0-fpm php7.0-json \
php7.0-mbstring php7.0-mcrypt php7.0-mysql php7.0-opcache php7.0-readline \
libapache2-mod-php7.0
RUN a2enmod rewrite
EXPOSE 80
RUN mkdir -p /var/www/html/myawesomesite.com/httpdocs
RUN mkdir -p /var/www/myawesomesite.com/logs/
COPY ./conf/myawesomesite.conf /etc/apache2/sites-available/
RUN a2ensite myawesomesite
RUN a2dissite 000-default.conf
CMD /usr/sbin/apache2ctl -D FOREGROUND
构建并运行容器,index.php正在正确执行,但是当这个页面myawesomesite.com/cgi-bin/helloworld.pl
刚刚打印出来的脚本没有执行时。结果如下:
#!/usr/bin/perl
print "Content-Type:text/html\n\n";
print "Hello World!";
我希望结果是Hello World!
,因为我在myawesomesite.conf文件中添加了这些指令。但为什么呢?
Options ExecCGI
AddHandler cgi-script .pl
答案 0 :(得分:1)
尝试添加到您的Dockerfile:
RUN chmod +x cgi-bin/helloworld.pl
CGI脚本必须设置可执行位。
答案 1 :(得分:0)
我必须将RUN a2enmod cgid
添加到Dockerfile并将以下块添加到conf(假设perl脚本已复制到/var/www/myawesomesite.com/www/cgi-bin/
):
<Directory "/var/www/myawesomesite.com/www/cgi-bin/">
Options +ExecCGI
AddHandler cgi-script .pl
</Directory>