
Ubuntu日本語フォーラム

ログインしていません。
以下に以前教わった設定をコピーしておきます。それと実際にWeb上につなげる設定はどうすればよいのでしょうか?よろしくお願いいたします。
/etc/apache2/mods-enabled/mime.conf と言うファイルに
#AddHandler cgi-script .cgi
と言う記述がありますので、「#」を外して、
AddHandler cgi-script .cgi .rb .pl
と「.rb」を付け加えてください。
それから、設定の管理方法によって様々なんですが、他に設定ファイルを作成してないとして
/etc/apache2/sites-available/default と言うファイルの
変更前 による投稿:
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
を
変更後 による投稿:
<directory /var/www/>
Options Includes ExecCGI FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
</directory>
とかしてみてください。.rbファイルやhtmlファイルは/var/www以下に配置することになります。
設定をいじったら、復活の呪文を唱えることを忘れずに。
コード:
sudo /etc/init.d/apache2 restart
また、ファイル管理上ログインユーザのディレクトリで公開したほうが楽だという場合、
<Directory /home/*/public_html>
AllowOverride All
Options IncludesNoExec ExecCGI FollowSymLinks
</Directory>
オフライン
.cgi ファイルに、実行権は付いてますか?
オフライン
実行権って分かりませんでした。グーグルで調べたのでがわかりません。やり方を教えてください。よろしく願いたします。
オフライン
※規約違反により追放されたユーザの投稿は、ログインユーザにのみ表示されます。
オフライン
cgi ファイルは、apache ユーザが起動する実行ファイルですので、ファイルに実行権が付いていなければ実行されません。
例で、説明します。
以下が、私の /var/www/html のディレクトリ・リストです。
$ ls -l /var/www/html
合計 36
drwxr-xr-x 2 root root 4096 2009-12-29 23:41 admin
-rw-r--r-- 1 root root 3638 2010-01-03 00:56 favicon.ico
drwxr-xr-x 2 root root 4096 2010-01-18 23:36 img
-rwxr-xr-x 1 root root 590 2010-01-05 13:35 index.cgi
-rw-r--r-- 1 root root 5 2010-01-04 18:47 index.html.bak
-rw-r--r-- 1 root root 23 2009-12-29 23:41 mobile.html
-rw-r--r-- 1 root root 224 2010-01-18 23:40 ooo-test.html
-rw-r--r-- 1 root root 14 2009-12-29 23:41 pc.html
drwxr-xr-x 2 root root 4096 2009-12-29 23:41 users
ここで、ファイルやディレクトリ行の先頭に表示されているアルファベット文字が、windowsで言えばファイルの属性見たいなものを表しています。
これを、ファイルのアクセス権限(パーミッション)と云います。
一番先頭の、「d」 は、ディレクトリであるかどうかを表し、- であればファイルです。他に [l] と云うのがあり、これはリンクであることを表します。
次からの 9 文字は、3文字ずつ区切って読みます。
左から、所有者のアクセス権限、次が、グループのアクセス権限、最後が他者(Others)のアクセス権限です。
3文字の意味は、左から、r (Read)は、読み込み可、- は、読み込み不可
次が、w (Write)は、書き込み(変更)可能、- は書き込み不可
最後が、x (eXecute)は実行可能、- は 実行不可 となっています。この実行権がファイルに付いてないと、コマンドとして機能しません。
実は、この文字は、単に、ファイルのパーミッションを表す、ビット列でそれぞれを表現する位置のビットが立っているかどうかを、分かり易く表示しているだけです。
例えば、上記、 index.cgi は、-rwxr-xr-x となっていますが、これは
0 111 101 101 (8進数表示で 755 ) と言うことです。
このパーミッションを変更するには、「chmod」コマンドを使います。
例、上記、 index.cgi から、全てユーザの実行権を取る
$ sudo chmod ugo-x /var/www/html/index.cgi
元に戻す
$ sudo chmod +x /var/www/html/index.cgi
8進数で全体を指定する
$ sudo chmod 755 /var/www/html/index.cgi
さて、この index.cgi の所有者、グループは、root root ですので、apache の実行時ユーザ www-data は 他者(Other) ですので、-rwxr-xr-x の右端が、x になっていなければ、cgi として実行できません。
?inux 系のOS では、ユーザ、グループとパーミションを意識していないと、いけません。
さらに最近では、セキュリティアップのための機構も組み込まれてきてますので、サーバを立てる時には、そこも考慮する必要が出てきました。
Ubuntuでは、Apparmor というセキュリティ機構として組み込まれていて、重要なアプリ、ツールは、その監視下に置かれ、不適切なファイル/ディレクトリ・アクセスは拒否されるようになっています。
オフライン
cgi-bin # chmod a+x index.cgiのように、実行権を与えたのにやはり、〜.cgiでは動きません。
cgiファイルはhttp://localhost/cgi-bin/index.cgiに置いてあります。
どこが間違っているのでしょうか。よろしくお願いいたします。どなたか教えてください。
オフライン
toukoさん による投稿:
cgiファイルはhttp://localhost/cgi-bin/index.cgiに置いてあります。
/var/wwwに直接置くとどうなりますか?
オフライン
zaganさん>
Internal Server Errorと表示されるだけでダメでした。
オフライン
/etc/apache2/mods-enabled/mime.confの内容を確認した方がよさそうですね。
内容を貼り付けてくださいませんか?
それと、以前の投稿に書いておきましたが、
1)サーバーをインターネットに公開するかしないか
2)アクセス時のURLをhttp://loocalhost/とかのドメイン直下に指定したいか、http://localhost/~touko/などのユーザーディレクトリ毎の公開にしたいか。
3)サーバーサイドスクリプトはrubyだけで良いのか。
4)DBサーバの要不要。
についてお答えいただくと、回答者側が助かります。
オフライン
1)サーバーをインターネット公開しない
2)アクセス時のURLをhttp://loocalhost/とかのドメイン直下に指定したい
3)サーバーサイドスクリプトはrubyだけで良い。
4)DBサーバの不要です。。
/etc/apache2/mods-enabled/mime.confの内容は以下のとおりです。
よろしくお願いいたします。
<IfModule mod_mime.c>
#
# TypesConfig points to the file containing the list of mappings from
# filename extension to MIME-type.
#
TypesConfig /etc/mime.types
#
# AddType allows you to add to or override the MIME configuration
# file mime.types for specific file types.
#
#AddType application/x-gzip .tgz
#
# AddEncoding allows you to have certain browsers uncompress
# information on the fly. Note: Not all browsers support this.
# Despite the name similarity, the following Add* directives have
# nothing to do with the FancyIndexing customization directives above.
#
#AddEncoding x-compress .Z
#AddEncoding x-gzip .gz .tgz
#AddEncoding x-bzip2 .bz2
#
# If the AddEncoding directives above are commented-out, then you
# probably should define those extensions to indicate media types:
#
AddType application/x-compress .Z
AddType application/x-gzip .gz .tgz
AddType application/x-bzip2 .bz2
#
# DefaultLanguage and AddLanguage allows you to specify the language of
# a document. You can then use content negotiation to give a browser a
# file in a language the user can understand.
#
# Specify a default language. This means that all data
# going out without a specific language tag (see below) will
# be marked with this one. You probably do NOT want to set
# this unless you are sure it is correct for all cases.
#
# * It is generally better to not mark a page as
# * being a certain language than marking it with the wrong
# * language!
#
# DefaultLanguage nl
#
# Note 1: The suffix does not have to be the same as the language
# keyword --- those with documents in Polish (whose net-standard
# language code is pl) may wish to use "AddLanguage pl .po" to
# avoid the ambiguity with the common suffix for perl scripts.
#
# Note 2: The example entries below illustrate that in some cases
# the two character 'Language' abbreviation is not identical to
# the two character 'Country' code for its country,
# E.g. 'Danmark/dk' versus 'Danish/da'.
#
# Note 3: In the case of 'ltz' we violate the RFC by using a three char
# specifier. There is 'work in progress' to fix this and get
# the reference data for rfc1766 cleaned up.
#
# Catalan (ca) - Croatian (hr) - Czech (cs) - Danish (da) - Dutch (nl)
# English (en) - Esperanto (eo) - Estonian (et) - French (fr) - German (de)
# Greek-Modern (el) - Hebrew (he) - Italian (it) - Japanese (ja)
# Korean (ko) - Luxembourgeois* (ltz) - Norwegian Nynorsk (nn)
# Norwegian (no) - Polish (pl) - Portugese (pt)
# Brazilian Portuguese (pt-BR) - Russian (ru) - Swedish (sv)
# Simplified Chinese (zh-CN) - Spanish (es) - Traditional Chinese (zh-TW)
#
AddLanguage ca .ca
AddLanguage cs .cz .cs
AddLanguage da .dk
AddLanguage de .de
AddLanguage el .el
AddLanguage en .en
AddLanguage eo .eo
# See README.Debian for Spanish
AddLanguage es .es
AddLanguage et .et
AddLanguage fr .fr
AddLanguage he .he
AddLanguage hr .hr
AddLanguage it .it
AddLanguage ja .ja
AddLanguage ko .ko
AddLanguage ltz .ltz
AddLanguage nl .nl
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pl .po
AddLanguage pt .pt
AddLanguage pt-BR .pt-br
AddLanguage ru .ru
AddLanguage sv .sv
# See README.Debian for Turkish
AddLanguage tr .tr
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw
#
# Commonly used filename extensions to character sets. You probably
# want to avoid clashes with the language extensions, unless you
# are good at carefully testing your setup after each change.
# See http://www.iana.org/assignments/character-sets for the
# official list of charset names and their respective RFCs.
#
AddCharset us-ascii .ascii .us-ascii
AddCharset ISO-8859-1 .iso8859-1 .latin1
AddCharset ISO-8859-2 .iso8859-2 .latin2 .cen
AddCharset ISO-8859-3 .iso8859-3 .latin3
AddCharset ISO-8859-4 .iso8859-4 .latin4
AddCharset ISO-8859-5 .iso8859-5 .cyr .iso-ru
AddCharset ISO-8859-6 .iso8859-6 .arb .arabic
AddCharset ISO-8859-7 .iso8859-7 .grk .greek
AddCharset ISO-8859-8 .iso8859-8 .heb .hebrew
AddCharset ISO-8859-9 .iso8859-9 .latin5 .trk
AddCharset ISO-8859-10 .iso8859-10 .latin6
AddCharset ISO-8859-13 .iso8859-13
AddCharset ISO-8859-14 .iso8859-14 .latin8
AddCharset ISO-8859-15 .iso8859-15 .latin9
AddCharset ISO-8859-16 .iso8859-16 .latin10
AddCharset ISO-2022-JP .iso2022-jp .jis
AddCharset ISO-2022-KR .iso2022-kr .kis
AddCharset ISO-2022-CN .iso2022-cn .cis
AddCharset Big5 .Big5 .big5 .b5
AddCharset cn-Big5 .cn-big5
# For russian, more than one charset is used (depends on client, mostly):
AddCharset WINDOWS-1251 .cp-1251 .win-1251
AddCharset CP866 .cp866
AddCharset KOI8 .koi8
AddCharset KOI8-E .koi8-e
AddCharset KOI8-r .koi8-r .koi8-ru
AddCharset KOI8-U .koi8-u
AddCharset KOI8-ru .koi8-uk .ua
AddCharset ISO-10646-UCS-2 .ucs2
AddCharset ISO-10646-UCS-4 .ucs4
AddCharset UTF-7 .utf7
AddCharset UTF-8 .utf8
AddCharset UTF-16 .utf16
AddCharset UTF-16BE .utf16be
AddCharset UTF-16LE .utf16le
AddCharset UTF-32 .utf32
AddCharset UTF-32BE .utf32be
AddCharset UTF-32LE .utf32le
AddCharset euc-cn .euc-cn
AddCharset euc-gb .euc-gb
AddCharset euc-jp .euc-jp
AddCharset euc-kr .euc-kr
#Not sure how euc-tw got in - IANA doesn't list it???
AddCharset EUC-TW .euc-tw
AddCharset gb2312 .gb2312 .gb
AddCharset iso-10646-ucs-2 .ucs-2 .iso-10646-ucs-2
AddCharset iso-10646-ucs-4 .ucs-4 .iso-10646-ucs-4
AddCharset shift_jis .shift_jis .sjis
#
# AddHandler allows you to map certain file extensions to "handlers":
# actions unrelated to filetype. These can be either built into the server
# or added with the Action directive (see below)
#
# To use CGI scripts outside of ScriptAliased directories:
# (You will also need to add "ExecCGI" to the "Options" directive.)
#
AddHandler cgi-script .cgi .rb .pl
#
# For files that include their own HTTP headers:
#
#AddHandler send-as-is asis
#
# For server-parsed imagemap files:
#
#AddHandler imap-file map
#
# For type maps (negotiated resources):
# (This is enabled by default to allow the Apache "It Worked" page
# to be distributed in multiple languages.)
#
AddHandler type-map var
#
# Filters allow you to process content before it is sent to the client.
#
# To parse .shtml files for server-side includes (SSI):
# (You will also need to add "Includes" to the "Options" directive.)
#
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
</IfModule>
オフライン
toukoさん による投稿:
1)サーバーをインターネット公開しない
2)アクセス時のURLをhttp://loocalhost/とかのドメイン直下に指定したい
3)サーバーサイドスクリプトはrubyだけで良い。
4)DBサーバの不要です。。
お手数でした。ありがとうございます。
では、/etc/apache2/sites-enabled/000-defaultに以下を追加してみてください。
まず、既に設定されている内容を「#」をつけて無効化します。(強調のため、赤文字にしてます)
# ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
# <Directory "/usr/lib/cgi-bin">
# AllowOverride None
# Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
# Order allow,deny
# Allow from all
# </Directory>
新たに、/var/www/cgi-bin/ディレクトリでcgiが動作するよう指定します。
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin/">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
そしてapache2の再起動のおまじない
sudo /etc/init.d/apache2 restart
エラーメッセージが表示されたら、それを貼り付けてください。
ただし、以下の内容は蒸しして構いません。
apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
... waiting apache2: Could not reliably determine the server's fully qualified domain name, using 127.0.1.1 for ServerName
cgiファイルを実行して動作しない場合、「システム」->「システム管理」->「ログビューア」で、/var/log/apache2/access.logと/var/log/apache2/error.logを開いて、メッセージを確認、張り付けてください。
なお、cgiファイルに関しては門外漢なので、識者にお任せします。
ではおやすみなさい。
オフライン
やはり動きませんでした。以下がその時のエラーメッセージです。よろしくお願いたします。
エラーメッセージ
* Restarting web server apache2 * We failed to correctly shutdown apache, so we're now killing all running apache processes. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!
... waiting .Syntax error on line 46 of /etc/apache2/sites-enabled/000-default:
Illegal option SymLinkslfOwnerMatch
/var/log/apache2/access.log
127.0.0.1 - - [08/Feb/2010:22:36:55 +0900] "GET /home/cgi-bin/index.cgi HTTP/1.1" 404 244 "-" "Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.17) Gecko/2010010604 Linux Mint/7 (Gloria) Firefox/3.0.17"
/var/log/apache2/error.log
[Mon Feb 08 21:38:21 2010] [error] [client 127.0.0.1] script not found or unable to stat: /var/www/index.cgi
オフライン
toukoさん による投稿:
エラーメッセージ
* Restarting web server apache2 * We failed to correctly shutdown apache, so we're now killing all running apache processes. This is almost certainly suboptimal, so please make sure your system is working as you'd expect now!
... waiting .Syntax error on line 46 of /etc/apache2/sites-enabled/000-default:
Illegal option SymLinkslfOwnerMatch
46行めがおかしいって言ってますね。
/etc/apache2/sites-enabled/000-defaultの設定例を以下に示しておきます。
既存のものと見比べて修正するか、コピーアンドペーストしてapache2を再起動させてください。
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
# ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
# <Directory "/usr/lib/cgi-bin">
# AllowOverride None
# Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
# Order allow,deny
# Allow from all
# </Directory>
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin/">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
設定ファイルを修正したら、apache2を再起動させます。
sudo /etc/init.d/apache2 restart
を忘れずに。
toukoさん による投稿:
/var/log/apache2/error.log
[Mon Feb 08 21:38:21 2010] [error] [client 127.0.0.1] script not found or unable to stat: /var/www/index.cgi
cgi-bin配下にindex.cgiをおいて、
http://localhost/cgi-bin/index.cgi
でいかがでしょう。
#!/usr/bin/perl
print "Content-type: text/html\n\n";
print "<html><head><title>CGI-Perl TEST</title>\n";
print "<meta http-equiv='content-type' content='text/html; charset=utf-8'>\n";
print "</head><body><h2>CGI-Perlテスト</h2>\n";
print "</body></html>\n";
exit;
こういう内容でファイルをcgi-binに置いたところ、「CGI-Perlテスト」と表示されました。
オフライン
どうやっても動きません。もし参考になさってる書籍とかあったら教えてください。またもうすこし間をおいて質問したいと思っています。よろしくお願いいたします。
オフライン
toukoさん による投稿:
どうやっても動きません。もし参考になさってる書籍とかあったら教えてください。
書籍は特にありません。忘れた事柄はwebを参考にしていますが、特定のサイトはあまりありません。
ご存知のように雛形の設定が用意されていますので、必要箇所を書き換えるだけです。
強いてあげるとすると、Apache.orgのドキュメントでしょうか。
念のためにUbuntuでCGIを動作させる手順を書いておきますね。
まず方針ですが
1)外部に公開しない。ローカルなサーバ。
2)スクリプト言語はrubyを使用。
3)ドキュメントルートは、/var/wwwに指定。
4)拡張子は .rb .cgi で動作するよう指定。
【1. インストール】
Synapticからapache2を選択してインストール
Synapticからruby1.9.1, ruby1.9.1-dev, rubygems1.9.1 をインストール(←rubyは分かりません。Webを参考にしました。)
【2. apache2の設定】
/etc/apache2/mods-enabled/mime.confの163行あたりのAddHandler cgi-script .cgiの行頭の「#」を外し、.rb .cgi を加筆。
/etc/apache2/sites-enabled/000-defaultを以下のように修正。
<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www
<Directory />
Options FollowSymLinks
AllowOverride None
</Directory>
<Directory /var/www/>
Options Indexes FollowSymLinks MultiViews
AllowOverride None
Order allow,deny
allow from all
</Directory>
# ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
# <Directory "/usr/lib/cgi-bin">
# AllowOverride None
# Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
# Order allow,deny
# Allow from all
# </Directory>
ScriptAlias /cgi-bin/ /var/www/cgi-bin/
<Directory "/var/www/cgi-bin/">
AllowOverride None
Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
Order allow,deny
Allow from all
</Directory>
ErrorLog /var/log/apache2/error.log
# Possible values include: debug, info, notice, warn, error, crit,
# alert, emerg.
LogLevel warn
CustomLog /var/log/apache2/access.log combined
Alias /doc/ "/usr/share/doc/"
<Directory "/usr/share/doc/">
Options Indexes MultiViews FollowSymLinks
AllowOverride None
Order deny,allow
Deny from all
Allow from 127.0.0.0/255.0.0.0 ::1/128
</Directory>
</VirtualHost>
設定を有効にするため、apache2を再起動。
sudo /etc/init.d/apache2 restart
【3. cgi格納ディレクトリの作成】
/var/www以下にcgi-binディレクトリを作成。
実行ファイルを/var/www/cgi-bin以下に配置。実行権の付与。
これで動かないとすると、cgiファイルの動作確認が必要かもしれません。
オフライン
ありがとうございます! やっと表示されました!とてもうれしいです。ありがとうございました!
オフライン