• ベストアンサー

ユーザー毎のディレクトリでCGIを設置

ユーザー毎のディレクトリでCGIを設置可能にしようとしているのですが、うまくいきません。 教えて下さい。 【環境】 Apache/2.0.40 Red Hat Linux 8.0 【httpd.confの設定抜粋】 DocumentRoot "/home/homepage/public_html" <Directory /home/homepage/public_html> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> <IfModule mod_userdir.c> UserDir public_html </IfModule> <Directory /home/*/public_html> Options Indexes FollowSymLinks AllowOverride All Order allow,deny Allow from all </Directory> #ScriptAlias /cgi-bin/ "/home/homepage/public_html/cgi-bin/" 【.htaccessの設定】 AddHandler cgi-script .cgi Options +ExecCGI 以上のような設定で #!/usr/bin/perl print "Content-type: text/html\n\n"; print "hello"; こんなCGIをつくって実行してみました。 /home/homepage/public_html/cgi-bin/においたものはうまくいくのですが /home/user/public_html/cgi-bin/においたものはエラーになってしまいます。 エラーの内容は↓のとおりです。 Server error! The server encountered an internal error and was unable to complete your request. Error message: Premature end of script headers: hello.cgi If you think this is a server error, please contact the webmaster Error 500 perlのパスは間違ってないし、パーミッションも755にしてあります。 どうすればいいのか分からず困っています。 どこを調べれみればいいのかだけでも教えていただけると助かります。 よろしくお願いします。

  • shi51
  • お礼率66% (2/3)

質問者が選んだベストアンサー

  • ベストアンサー
  • astronaut
  • ベストアンサー率58% (303/516)
回答No.3

RedHatのhttpdはsuexecが有効にされていて、ユーザーディレクトリでは、public_html 直下でしかcgi が実行できません。 /usr/sbin/suexec のファイル名を変更すれば、public_html 以下の任意のディレクトリで cgi が実行できるようになります。

shi51
質問者

お礼

うごきました!! suexecファイルを別の名前に変更して、Apacheを再起動してみたところ無事に「hello」と表示されました。 そのとき「#!/usr/bin/perl/」を「#!/usr/bin/perl/ --」にしておくとうまくいきました。 本当にありがとうございました。

その他の回答 (2)

  • nota55
  • ベストアンサー率37% (138/366)
回答No.2

ありゃ,ダメでしたか。 んじゃ, 1.うまくいかない方のcgiファイルの改行コードを確認 →誤認識されるという話を聞いたことがあります。  LFで保存し直してみて下さい。 2.おまじないに手を加える →「#!/usr/bin/perl/」を「#!/usr/bin/perl/ --」に あたりはどうでしょ。 念のため, ・さっきコメントを外した部分はそのまま ・コメントを外した部分を再度コメントアウト の2パターンで試してみて下さい。

shi51
質問者

お礼

「#!/usr/bin/perl/」を「#!/usr/bin/perl/ --」に変更する方法はとても役に立ちました。 本当にありがとうございました。

shi51
質問者

補足

またまたありございます。 何度もすみません。 早速試してみました。 1.改行コードをLFで保存+先ほどの部分をコメント 2.改行コードをLFで保存+先ほどの部分をコメントアウト 3.「#!/usr/bin/perl/ --」+先ほどの部分をコメント 4.「#!/usr/bin/perl/ --」+先ほどの部分をコメントアウト ↑の4種類を試してみましたが、まだダメみたいです。 すいません。

  • nota55
  • ベストアンサー率37% (138/366)
回答No.1

#ScriptAlias /cgi-bin/ "/home/homepage/public_html/cgi-bin/" ここがコメントアウトされているからでは? コメントアウトされてると user/public_html/cgi-bin/ が /home/homepage/public_html/cgi-bin/に マッピングされないような気が。

shi51
質問者

補足

早速の回答ありがとうございます。 ScriptAlias /cgi-bin/ "/home/homepage/public_html/cgi-bin/" コメントアウトしてみましたが同じエラーのままでした。

関連するQ&A

  • Redhat9のHTTPDでCGIがつかえない

    まずやりたい事はユーザーごとにWEBができるようにして、CGIをpublic_html以下のどこにでもCGIが使えるようにしたい思っています。 いろんなサイトを見てhttpd.confをいじってますが、どうしてもCGIを実行しても500エラーがでます。perlの場所はあっているんですが。 httpd.confのいじった所は、 <IfModule mod_userdir.c> UserDir public_html </IfModule> と <Directory /home/*/public_html> AllowOverride FileInfo AuthConfig Limit Options IncludesNoExec ExecCGI FollowSymLinks <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> と ScriptAlias /cgi-bin/ "/var/www/cgi-bin/"をコメントアウトしました。もしよろしければご指導のほどよろしくおねがいします。

  • cgi-binにアクセスできない

    apache初心者です。 Turbolinux6.0+apache1.3.12でHTTPサーバを試しているのですが、 cgi-binにあるファイルを見ようとするとHTTP 403エラーが出て表示できません。 属性とグループを色々変えてみたんですが、だめでした。 access.confで関係ありそうな所は <Directory /> Options None AllowOverride None order allow,deny allow from all </Directory> <Directory /home/httpd/html> Options Indexes Includes FollowSymLinks AllowOverride None order allow,deny allow from all </Directory> <Directory /home/httpd/cgi-bin> AllowOverride None Options FollowSymlinks ExecCGI order allow,deny allow from all </Directory> としていますが、なぜcgi-binの中身が見えないのかわかりません。 よろしくおねがいします。

  • Apach2.0 ホームディレクトリでCGIが

    こんにちは。 CGIの勉強をしています。 わかる方がいらっしゃいましたら、おしえてください。 ソースは、poderosaでつないでviにて作成。 ブラウザからのアクセス http://XXX.XXX.XXX.XXX/~admin/cgi-bin/test.cgi (test.cgi)755 #!/usr/bin/perl print "Content-type: text/html\n\n"; print "Hello\n"; ./test.cgi にて、Helloと表示される (httpd.confに追加したもの) UserDir public_html <Directory /home/*/public_html> AllowOverride All Options IncludesNoExec ExecCGI FollowSymLinks <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> 以下を追加したこともあり↓ <Directory /home/*/public_html/cgi-bin/> AllowOverride None Options ExecCGI SetHandler cgi-script Order allow,deny Allow from all AddHandler cgi-script .cgi </Directory> よろしくおねがいします。

  • Apacheでのユーザーディレクトリ生成

    現在fedora core4 -Apache- でサーバー構築を勉強中なのですが、どうしても解決できない問題が出ました。それはユーザーディレクトリを生成した後、そのディレクトリにアクセスできないという問題です。 ユーザー[testuser]を追加し、/home/testuser/public_htmlを作成後 /home/testuser/public_html/index.htmlを作成、 httpd.confの設定を <IfModule mod_userdir.c> #UserDir disable UserDir /home/*/public_html/ </IfModule> # # Control access to UserDir directories. The following is an example # for a site where these directories are restricted to read-only. # #<Directory /home/*/public_html> # AllowOverride FileInfo AuthConfig Limit # Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Directory /home/*/public_html> AllowOverride All Options IncludesNoExec ExecCGI FollowSymLinks <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> とし、ttp://www.testsrv.net/~testuserにアクセスしたところ、 You don't have permission to access /~user1 on this server. アクセス権が無いとはじかれました。 この場合、アクセスできるようにするにはどのようにすれば良いのでしょうか?

  • httpd.confを添削してください!!(長文)

    こんにちわ いろいろと調べながらhttpd.confを自分の理想の動作を得るたねに設定したつもりです。 添削をお願いします。 /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ DocumentRoot /var/www/html <Directory /> Options FollowSymLinks AllowOverride All </Directory> <Directory "/var/www/html"> #←home Options FollowSymLinks Includes AllowOverride All Order allow,deny Allow from all </Directory> #.htaccessを許可、cgiは不可、ssiは許可、シンボリックリンク許可 Order~略 <IfModule mod_userdir.c> UserDir public_html </IfModule> <Directory /home/*/public_html> AllowOverride AuthConfig Limit Options +ExecCGI +Includes </Directory> #ユーザー領域では.htaccessで認証、アクセス元などで制御の許可。 それ以外は不可。 homeでcgiが不可ですがここでは許可したいので+を付けた。 <Directory "/var/www/cgi-bin"> AllowOverride All Options ExecCGI Order allow,deny Allow from all AddHandler image .gif .jpg AddHandler text/html .htm .html </Directory> /_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/ こんな感じなんですがどこかおかしいでしょうか?

  • Fedora Apache ユーザディレクトリの設定 /をつけないと表示されない!

    Fedora CoreのApacheでユーザディレクトリのコンテンツを公開するため、下記のように設定しました。 <IfModule mod_userdir.c> UserDir public_html </IfModule> <Directory /home/*/public_html> AllowOverride All Options IncludesNoExec ExecCGI FollowSymLinks <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> で、ばっちり見れるようになったんですが、下記のような問題が残っています。 http://ホストアドレス/~ユーザ名/ では正常に表示されるが、 http://ホストアドレス/~ユーザ名 のようにスラッシュを省略すると、表示されない。 ご存知の方おられましたらよろしくお願いしますー!

  • /cgi-bin/のファイル読み出し

    WindowsXPでApacheをlocalhostで使用しています。 httpd.confを以下のように設定してcgiは問題なく作動していますが、/cgi-bin/に置いた画像やhtmlが読み出せません (すなわちhttp://localhost/cgi-bin/にアクセス出来ず、Forbiddenのエラーが出ます) 今は仕方なく、cgiで使用するファイルや画像をDocumentRoot配下に置いていますが、/cgi-bin/配下のファイルを読み出すhttpd.confの設定を教えて下さい。 DocumentRoot "F:/" <Directory /> Options FollowSymLinks AllowOverride None </Directory> <Directory "F:/"> AllowOverride None Order allow,deny Allow from all </Directory> <IfModule mod_alias.c> ScriptAlias /cgi-bin/ "F:/cgi-bin/" <Directory "F:/cgi-bin"> AllowOverride None Options ExecCGI MultiViews Order allow,deny Allow from all </Directory> </IfModule>

  • Fedora Core1サーバーでCGIが利用できません

    Fedora Core1でwebサーバーを立てたのですが、実行しようとすると「500 Internal Server Error」となってCGIが動きません。 perlへのパスやパーミッションの設定も見直しましたが、どこの設定が間違っているか分からないので、設定方法を教えてもらえないでしょうか? 現在の環境は ホスト名:saba.dyndns.org perlのパス:/usr/local/bin/perl CGIを仕えるようにしたいユーザー:guest CGIを設置するディレクトリ:/home/guest/cgi-bin/ Apacheのバージョンは2.0.49 となっています。 また以下はhttpd.confの抜粋です。 Listen *:80 #ScriptAlias /cgi-bin/ "/var/www/html/" ScriptAlias /cgi-bin/ "/home/guest/public_html/cgi-bin/" AddHandler cgi-script .cgi .pl <Directory "/home/guest/public_html/"> Options ExecCGI AllowOverride None Allow from all Order allow,deny </Directory> <Directory /home/*/public_html> AllowOverride FileInfo AuthConfig Limit Options Includes ExecCGI FollowSymLinks <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> 長文失礼しました。

  • apacheのユーザーディレクトリの設定

    Fedora Core6のapacheのユーザーディレクトリの設定で悩んでいます。 設定ファイル(httpd.conf)には以下のように記述しています。 #UserDir disable UserDir public_html <Directory /home/*/public_html> AllowOverride FileInfo AuthConfig Limit Options MultiViews Indexes SymLinksIfOwnerMatch IncludesNoExec <Limit GET POST OPTIONS> Order allow,deny Allow from all </Limit> <LimitExcept GET POST OPTIONS> Order deny,allow Deny from all </LimitExcept> </Directory> ユーザー登録をして/home/ユーザ名/にpublic_htmlフォルダを作成して、index.htmlページを作り、http://localhost/~ユーザー名/index.htmlにアクセスしましたが、「403 Forbidden」となってしまいます。 http://127.0.0.1/~ユーザー名/でアクセスしても「403 Forbidden」になります。 フォルダやファイルのパーミッションをいろいろと変えてみましたが表示されません。 こちらはLinux勉強中の初心者です。 よろしくお願いします。

  • apacheのCGI設定

     pc9821にFreeBSD(98)をいれapache1.3を起動させています。cgiはlight.cgiというソフトをつかっています。なかなかcgiがうまくいきません。参考ページには public_html / index.html (トップページ) | +-- bbs / light.cgi [755] | admin.cgi [755] ・・・・(省略) +-- lock [777] / | +-- past [777] / 0001.cgi [666] とかかれていますが、実際に私のサーバーにはpublic_htmlというフォルダは存在していなくて /usr/local/www/cgi-binにbbsというフォルダをつくり あとは上のようにしています。またindex.htmlは/usr/local/www/dataのなかにいれて表示してWebサーバーとしてはたらいています。またapacheの/usr/local/etc/apacheのhttpd.confは 関係ありそうな行だけあげると ServerRoot "/usr/local" DocumentRoot "/usr/local/www/cgi-bin" <Directory "/usr/local/www/cgi-bin/bbs"> Options Indexes FollowSymLinks MultiViews <location "/cgi-bin/"> Options ExecCGI AllowOverride AuthConfig Limit Order allow ,deny Allow from all </Location> <IfModule mod_mime.c> TypesConfig /usr/local/etc/apache/mime.types ADDHandler cgi-script .cgi </IfModule> ScriptAlias /cgi-bin/ "/usr/local/www/cgi-bin/" <Directory "/usr/local/www/cgi-bin/bbs"> AllowOverride None Options ExecCGI Order allow,deny Allow from all </Directory> AddHandler cgi-script .cgi どこがおかしいのかおしえていただけないでしょうか?

    • ベストアンサー
    • CGI