如何配置docker文件像perl一样运行cgi-script [英] How to configure the docker file to run cgi-script like perl

查看:19
本文介绍了如何配置docker文件像perl一样运行cgi-script的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个文件:

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

在/conf/myawesomesite.conf 中:

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>

在 Dockerfile 中:

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

构建并运行容器,index.php 正在正确执行,但是当这个页面 myawesomesite.com/cgi-bin/helloworld.pl 脚本只是打印而不执行.结果如下:

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!";

我期待结果是 Hello World! 因为我在 myawesomesite.conf 文件中添加了这些指令.但为什么?

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

Options ExecCGIAddHandler cgi-script .pl

推荐答案

我必须将 RUN a2enmod cgid 添加到 Dockerfile 并将以下块添加到 conf(假设 perl 脚本已复制到 <代码>/var/www/myawesomesite.com/www/cgi-bin/):

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>

这篇关于如何配置docker文件像perl一样运行cgi-script的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆