我有以下文件:
- index.php
- Dockerfile
- /conf/myawesomesite.conf
- cgi-bin/helloworld.pl
/conf/myawesomesite.conf中包含:
<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