2017-02-21 49 views
2

我有這樣的文件:如何配置泊塢窗文件來運行CGI腳本如Perl

  • 的index.php
  • Dockerfile
  • /conf/myawesomesite.conf
  • 的cgi-bin/helloworld.pl

在/conf/myawesomesite.conf:

<VirtualHost *:80> 

    ServerAdmin [email protected] 
    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

回答

1

嘗試添加到您的Dockerfile:

RUN chmod +x cgi-bin/helloworld.pl 

CGI腳本必須設置可執行位。

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>