FLYING

/* TODO: 気の利いた説明を書く */

VPSを導入してやったこと(Apacheセットアップ編)

VPSを導入してやったこと(初期設定編)の続きです。

Apacheの設定を行う前に,現時点ではリモートにファイルを転送する手段がないので(ファイル転送の度にCygwinを起動してコマンドを打つのは面倒なので嫌),VPSFileZillaのSFTPモードで接続してみることにします。

FileZillaの設定画面から「接続」,「SFTP」と進み,ローカルに保存してある秘密鍵を指定します。Poderosaで生成した秘密鍵を使うためにはPuTTY秘密鍵フォーマットに変換する必要があるので,プロンプトに従って変換してやります。FileZillaVPSに接続する際にはサーバーの種類を「SFTP」にし,ログオンの種類を「インタラクティブ」にします。サーバーへの接続に時間が掛かるので,タイムアウトの設定も予め緩めておいたほうがいいでしょう>解決しました

FileZillaからVPSに接続できることを確認したら,SSH端末に戻ってApacheの設定ファイルを編集します。下記の項目をそれぞれ設定もしくはコメントインします。

$ sudo vim /etc/httpd/conf/httpd.conf
#
# If you wish httpd to run as a different user or group, you must run
# httpd as root initially and it will switch.  
#
# User/Group: The name (or #number) of the user/group to run httpd as.
#  . On SCO (ODT 3) use "User nouser" and "Group nogroup".
#  . On HPUX you may not be able to use shared memory as nobody, and the
#    suggested workaround is to create a user www and use that user.
#  NOTE that some kernels refuse to setgid(Group) or semctl(IPC_SET)
#  when the value of (unsigned)Group is above 60000; 
#  don't use Group #-1 on these systems!
#
User apache
Group apache

#
# ServerAdmin: Your address, where problems with the server should be
# e-mailed.  This address appears on some server-generated pages, such
# as error documents.  e.g. admin@your-domain.com
#
ServerAdmin root@tondol.com

#
# ServerName gives the name and port that the server uses to identify itself.
# This can often be determined automatically, but we recommend you specify
# it explicitly to prevent problems during startup.
#
# If this is not set to valid DNS name for your host, server-generated
# redirections will not work.  See also the UseCanonicalName directive.
#
# If your host doesn't have a registered DNS name, enter its IP address here.
# You will have to access it by its address anyway, and this will make 
# redirections work in a sensible way.
#
ServerName tondol.com:80

#
# DocumentRoot: The directory out of which you will serve your
# documents. By default, all requests are taken from this directory, but
# symbolic links and aliases may be used to point to other locations.
#
DocumentRoot "/home/tondol/public_html"

#
# This should be changed to whatever you set DocumentRoot to.
#
<Directory "/home/tondol/public_html">

続いて,Apacheの実行グループとDocumentRootの所有者のグループを統一します。これをやらないとApacheさんがDocumentRootにあるファイルを読み込むことができないので,後ですっごく困ることになります(困りました)。

ここでは「apache」という名前のグループを作成し,Apacheの実行ユーザーとDocumentRootの所有者を同グループに所属させることにしました。ちなみに,ここでホームディレクトリのパーミッションを変更しないとApacheがうまく動かないようなので注意してください(ブラウザでアクセスしても403エラーで閲覧不可になる)。

$ sudo /usr/sbin/groupadd apache
$ sudo /usr/sbin/usermod -G wheel,apache tondol
$ sudo /usr/sbin/usermod -g apache apache
$ chmod 711 .
$ mkdir public_html
$ chmod 755 public_html
$ chown -R tondol:tondol public_html
$ exit

一旦ログアウトしてログインし直します(グループの設定を有効にするため)。

Apacheを再起動してみましょう。

$ sudo /etc/init.d/httpd restart

ここまで完了したら,先ほど設定したFileZillaでローカルにあるindex.htmlをDocumentRootにアップします。

この段階でブラウザでVPSドメインにアクセスすると,アップしたindex.htmlの内容が表示されました。ここまでの作業でVPSを単純なHTTPサーバーとして動かすことができましたね!

Rubyインストール編に続く。