How to run test perl script as cgi script with htt

2019-08-17 13:59发布

问题:

I'm trying to follow this tutorial and run sample script under cgi.

Below are steps which I did:

1) Made sample script

$ cat > test.pl <<EOF
> #!/usr/bin/perl
> print "Content-type: text/html\n\n";
> print "Hello, World.";
EOF

2) run httpd docker container and mounted created script as volume in cgi-bin directory:

$ docker run --name cgi_test --rm -p 3000:80 -v $(pwd)/test.pl:/usr/local/apache2/cgi-bin/test.pl httpd

3) check if CGI module is enabled:

$ docker exec -it cgi_test cat /usr/local/apache2/conf/httpd.conf | grep modules/mod_cgid.so
    #LoadModule cgi_module modules/mod_cgid.so

CGI module was turned out so I enabled it:

$ docker exec -it cgi_test sed -i 's,#\(LoadModule cgid_module modules/mod_cgid.so\),\1,g' /usr/local/apache2/conf/httpd.conf

4) Checked ScriptAlias directive and enabling of alias_module :

$ docker exec -it cgi_test cat /usr/local/apache2/conf/httpd.conf | grep "ScriptAlias /cgi-bin/"
    ScriptAlias /cgi-bin/ "/usr/local/apache2/cgi-bin/"
$ docker exec -it cgi_test httpd -M | grep -e cgid -e alias
 cgid_module (shared)
 alias_module (shared)

It was ok

5) Checked exec permissions:

$ docker exec -it cgi_test ls -la /usr/local/apache2/cgi-bin/test.pl
-rwxr-xr-x 1 1000 1000 76 Mar 20 12:41 /usr/local/apache2/cgi-bin/test.pl

It was ok

6) Restarted httpd in docker container:

$ docker kill --signal="USR1" cgi_test

But when I to to http://localhost:3000/cgi-bin/test.pl I see 503 Service Unavailable and this error in log:

[Wed Mar 20 19:03:02.323430 2019] [cgid:error] [pid 1446:tid 139952364902144] (22)Invalid argument: [client 172.17.0.1:34328] AH01257: unable to connect to cgi daemon after multiple tries: /usr/local/apache2/cgi-bin/test.pl

What else I need to do to run script ?

回答1:

To make everything work I was needed to restart httpd twice instead of once :

docker kill --signal="USR1" cgi_test  # (x2)

I thought maybe it's USR1 signal (Graceful Restart) issue , but i had same with HUP signal (Restart Now). To apply changes I need to send signal twice. So looks like httpd container issue.