LoginSignup
0
2

More than 3 years have passed since last update.

Ubuntu 20.04 LTS で Apache2 + CGI エラー

Last updated at Posted at 2020-06-12

CGIを動かそうとしたら、

Service Unavailable
The server is temporarily unable to service your request due to maintenance downtime or capacity problems. Please try again later.

Apache/2.4.41 (Ubuntu) Server at 192.168.162.113 Port 80

となった。

環境

Ubuntu 20.04 LTS
Apache2

cgi のためにあらかじめ行っていた設定

apache2 をインストール。
apache の cgi モジュールをインストール


$ sudo a2enmod cgid

今回は、 /var/www 以下全てで CGI が動作するようにしました。


$ sudo vim /etc/apache2/apache2.conf

・・・
<Directory /var/www/>
        Options Indexes FollowSymLinks
        AllowOverride None
        Require all granted
</Directory>
・・・


・・・
<Directory /var/www/>
        Options Indexes FollowSymLinks execCGI
        AddHandler cgi-script .cgi .pl
        AllowOverride None
        Require all granted
</Directory>
・・・

ディレクトリ設定の確認。


$ sudo vim /etc/apache2/mods-enabled/dir.conf

以下のように設定されていました。


・・・
<IfModule mod_dir.c>
        DirectoryIndex index.html index.cgi index.pl index.php index.xhtml index.htm
</IfModule>
・・・

変更の反映


$ sudo service apache2 reload

エラー

ブラウザで開くと、冒頭のエラーが発生する。
/var/log/apache2/error.log には以下のように記録されていた。


[Fri Jun 12 11:12:24.086021 2020] [cgid:error] [pid 3340:tid 140420103878400] (22)Invalid argument: [client 192.168.162.32:51369] AH01257: unable to connect to cgi daemon after multiple tries: /var/www/html/indexserver.cgi, referer: http://192.168.162.113/

原因

cgid が動作する時にソケットファイルを必要としますが、その作成場所にパーミッションが不足しているらしいです。

対応

「(13) Permission denied on Apache CGI attempt」
https://serverfault.com/questions/142801/13-permission-denied-on-apache-cgi-attempt
を参照し、同様に対処することにしました。新たにソケットファイルの保管場所を作成し、設定する方法です。


$ sudo vim /etc/apache2/mods-available/cgid.conf 

として、編集


# Socket for cgid communication
ScriptSock ${APACHE_RUN_DIR}/cgisock

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

となっているのを、↓のように書き換える


# Socket for cgid communication
ScriptSock /var/run/httpd/cgisock

# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

$ cd /var/run
$ sudo mkdir httpd
$ sudo chown www-data:www-data httpd

として、apache2 を reload したら動作しました。

その後


[Fri Oct 16 10:10:54.453044 2020] [cgid:error] [pid 938] (2)No such file or directory: [client 192.168.162.67:53355] AH02833: ScriptSock /var/run/httpd/cgisock.929 does not exist: /var/www/html/index.cgi

というエラーが発生することがありました。
この場合、 /var/run/httpd が無かったので


$ cd /var/run
$ sudo mkdir httpd

として、apache2 を reload で対処しました。

0
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
2