OSX10.8サーバ その15 Webサーバその2

Mの更新(Mountain Lion OSX10.8サーバ) その15ーWebサーバ

各ユーザがWeb公開を行うための設定。

これまでは、http://[ドメイン名]/[ユーザ名]で /Users/[ユーザ名]/Sites のファイルが公開できていたわけだ。
ユーザ毎のバーチャルホストを建てることもできそうだがそんな面倒なことはしたくない。従来通りにしたい。用意されたファイルの構成がなかなか理解できず、苦労した。

1) httpd_server_app.confの書き換え
/library/server/web/config/apache2/httpd_server_app.conf の
# User home directories
#Include /private/etc/apache2/extra/httpd-userdir.conf
のInclude の行のコメントを外す。

# User home directories
Include /private/etc/apache2/extra/httpd-userdir.conf

だな。これでhttpd-userdir.conf が有効になる。

2) /private/etc/apache2/extra/httpd-userdir.conf の書き換え

ここには

# Users might not be in /Users/*/Sites, so use user-specific config files.

とあるので、個々のユーザのサイトの設定を書くために

Include /private/etc/apache2/users/*.conf

の行を加える。

ユーザ毎のサイトの設定ファイル httpd-[].conf を/private/etc/apache2/users/内に置いて有効にするためだ。

さらに、ここにエイリアスを作って~なしにする。たとえば;

http://example.com/~hoge/ の~がなくてもいいようにするために

Alias /hoge /users/hoge/Sites

の行を書き加える。

/private/etc/apache2/users/httpd-hoge.conf

各ユーザごとに必要となる。

[追記]

Server.appでWebサイトの指定を/Library/Server/Web/Data/Sites/Default にしてこのなかにシンボリックファイルを置けば(その1参照)~がなくてもいいことになる。

3) ユーザ毎の.confを作成する
/private/etc/apache2/users にある sample.conf  を httpd-[ユーザ名].conf として同じdirectoryにコピーし、できたhttpd-[ユーザ名].conの中身を

<Directory “/Users/[ユーザ名]/Sites/”>
Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all
</Directory>
<Directory “/Users/[ユーザ名]/Sites/cgi-bin/”>
Options +ExecCGI -Indexes -MultiViews
</Directory>

と書き換える。

.htaccess を有効にするには
AllowOverride None →  AllowOverride All

Option に書くのは
All                                                  Multiviews を除くすべて許可
None                                            すべて不許可
ExecCGI                                     CGI の許可
FollowSymLinks                     シンボリックリンクを許可
SymLinksIfOwnerMatch    オーナーならシンボリックリンクを許可
Includes                                   SSI を許可
IncludesNOExec                  exec を除く SSI を許可
Indexes                                    index.htmlがないときファイル一覧表示を許可
Multiviews          コンテントネゴシエーションを使用できる
+をつけると上位のdirectoryでの指定に加えてその機能を加える。-は上位のdirectoryでの指定からその機能を削除することになる。

これでhttp://[ドメイン名]/[~ユーザ名] でページが見えることになる。
ユーザは自分のdirectory(フォルダ)内にSitesというdirectory(フォルダ)を作成するとこの中身がWebページとして公開される。CGIを行いたいときはSitesの中にcgi-binというdirectory(フォルダ)を作成しCGIプログラムを書いたファイルを置く。

結局管理者のページに関しては/private/etc/apache2/usersにhttpd-hoge.confを作り、内容を;

<Directory “/Users/hoge/Sites/”>
Options Indexes MultiViews Includes FollowSymLinks
AllowOverride All
Order allow,deny
Allow from all
</Directory>
<Directory “/Users/hoge/Sites/cgi-bin/”>
Options +ExecCGI -Indexes -MultiViews
</Directory>

とした。つまりSites内では.htaccess が有効で、ファイル一覧が可、Multiviewsが有効、SSI を許可、シンボリックリンクを許可、この下のcgi-bin では.htaccessが使えて、ファイル一覧が不可、Multiviewsが不可、SSI を許可、シンボリックリンクを許可、CGI実行許可ということになる。Order allow,deny Allow from all は必要ないので削除だと思う。

おしまい。

要するにMountain Lion ServerではApache2 が参照する .conf ファイルはm通常のLinuxサーバが/etc/httpd/httpd.conf 等を参照しているのとはちがって、httpd_server_app.conf なのだ

そこで、各ユーザのサイトも有効にするための経路は;
/library/server/web/config/apache2/httpd_server_app.conf  (ともかくここが最初、有効な.confを定義する)

/private/etc/apache2/extra/httpd-userdir.conf  (これも有効な.conf となったので、必要に応じて改変する)

/private/etc/apache2/users/*.conf  (ユーザ毎の .conf を作成してユーザ毎の設定を書く)
という順なのだ。

しかも、/Users/*/Sitesのような定義は使うなということなので、ユーザ毎の .conf を作成することになったのだ。ユーザ数が少ないので問題ないのだ。

面倒だな。似たようなdirectoryの名前なので途中で何回も混乱した。

ん?CGIが動かない。原因調査中。

$$$$$$$$以下は失敗した試行$$$$$$$$$$$$$$$$$$$$$$
Mac のターミナルからリモートでssh接続していると、ちょいとトイレにいったりすると切れてしまう。そこで
/etc/ssh_config の一番下に
ClinerAliveInterval 30
ClientAliveCountMax 3
と記入した。
さらに使っているMacBookAirの自分のdirectoryの.ssh directory にconfig というファイルを作成し
ServerAliveInterval 30
ServerAliveCountMax 3
と書いてみた。どうなるだろ。30秒=毎に3回パケットを送り応答がないと切断するというわけだつまり90秒だ。いいのかな?

端末のほうの記述だとsshがエラーとなってうごかない。
失敗。

URLに~をつけたくない場合は
/Library/Server/Web/Data/Sites/Default でシンボリックリンクを作成する。
$ sudo ln -s Users/[ユーザ名]/Sites [ユーザ名]
[ユーザ名] -> Users/[ユーザ名]/Sites
というシンボリックリンクができる。
だめだ。どこに書いたらいいのか調査中。

/library/server/web/config/apache2/httpd_server_app.conf
が最初に読み込まれるファイルだから、このファイルに
#Users Sites config files
Include /private/etc/apache2/users/httpd-users.conf
と加筆し、
/private/etc/apache2/users/httpd-users.conf
に/private/etc/apache2/users/sample.confの内容が以下だから
/private/etc/apache2/users/sample.conf

Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all

Options +ExecCGI -Indexes -MultiViews

これをコピーしてhttpd-users.confというファイル名にして

Options Indexes MultiViews
AllowOverride None
Order allow,deny
Allow from all

Options +ExecCGI -Indexes -MultiViews

と変更したがだめである。

/private/etc/apache2/extra/httpd-userdir.confに
# Users might not be in /Users/*/Sites, so use user-specific config files.
という記述があるから、/Users/*/Sitesは使えないようだ。
さらに /private/etc/apache2/extra/httpd-userdir.confには
Include /private/etc/apache2/users/*.conf
とかいてあるから
/library/server/web/config/apache2/httpd_server_app.conf

Include /private/etc/apache2/extra/httpd-userdir.conf
として
/private/etc/apache2/extra/httpd-userdir.confに
Include /private/etc/apache2/users/*.confとあるので
/private/etc/apache2/usersにユーザ毎の.confをつくるのがいいらしい。

「OSX10.8サーバ その15 Webサーバその2」への2件のフィードバック

コメントを残す

メールアドレスが公開されることはありません。 * が付いている欄は必須項目です

このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください