How to configure the docker file to run cgi-script like perl

坚强是说给别人听的谎言 提交于 2021-01-21 08:31:49

问题


I have this files:

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

in /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>

in 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

build and run the container, index.php is executing correctly but when this page myawesomesite.com/cgi-bin/helloworld.pl the script is just printed not executed. Result below:

#!/usr/bin/perl

print "Content-Type:text/html\n\n";
print "Hello World!";

I'm expecting the result is Hello World! since i added these directives in my myawesomesite.conf file. But why?

Options ExecCGI AddHandler cgi-script .pl


回答1:


I had to add RUN a2enmod cgid to the Dockerfile and the following block to the conf (assuming the perl script was copied to /var/www/myawesomesite.com/www/cgi-bin/):

<Directory "/var/www/myawesomesite.com/www/cgi-bin/">
    Options +ExecCGI
    AddHandler cgi-script .pl
</Directory>



回答2:


Try to add to your Dockerfile:

RUN chmod +x cgi-bin/helloworld.pl

CGI scripts must have executable bits set.



来源:https://stackoverflow.com/questions/42363767/how-to-configure-the-docker-file-to-run-cgi-script-like-perl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!