Apache suexecモジュール設定

コンパイル時にデフォルトオプションにてsuexecを組み込み、各ユーザ( http://www.example.jp/~foo/ )配下でExecCGIを有効にしている場合に、以下のエラーとなる。

  • errors
.... Premature end of script headers: /home/foo/public_html/bar.cgi
  • suexec_log
.... user mismatch (nobody instead of www)

コンパイル時に"--with-suexec-caller"を指定しないと"www"というユーザで起動するようになる。これはApache付属のマニュアルには書いていない。因みに理由は、support/suexec.h にて、

/*
 * HTTPD_USER -- Define as the username under which Apache normally
 *               runs.  This is the only user allowed to execute
 *               this program.
 */
#ifndef AP_HTTPD_USER
#define AP_HTTPD_USER "www"
#endif

が有効になるため。

よって、httpd.confのUserディレクティブのユーザを"--with-suexec-caller"で指定する必要がある。

$ ./configure --with-suexec-caller="nobody" ....

それにしても、CGI起動時に"500 Internal Server Error"になるし、エラーログでも"Premature end of script headers"のエラーになっているので、てっきりCGIが問題だと思って随分とハマってしまった。