LoginSignup
2

More than 5 years have passed since last update.

Ubuntu の Apache2 とさくらインターネットのドメイン管理でバーチャルホストの設定のメモ

Last updated at Posted at 2015-11-14

始めに

同様な内容について有益な記事が他に多数ある中、あまり一般性のない内容の記事を自分へのメモとして僭越ながらこの場に置かしていただきました次第にございますれば、効率的でない点や間違っている箇所の御指摘などいただけましたら僥倖にございます。

要件

apache2 のバーチャルホストの設定は、名前で分ける場合とか IP で分ける場合とかいろいろございますが、このメモの要件は以下でございます

  • サーバは Ubuntu Trusty です
  • IP Address は一つしかないです、ので名前でバーチャルホストを作ります
  • ドメインはさくらインターネットでとってもらったので、さくらの管理ツールで管理してます
  • 関係ないかもしれないけど一応、サーバは scaleway の C1 です

以下、ドメインを domain.comとして、サーバのホスト名を host、仮想ホスト名を v-host、仮想サーバのドキュメントルートを /var/www/v-host にするものとして例示させていただきます

手順

Ubuntu 側の設定

sites-available の作成

/etc/apache2/sites-available/000-defalut.conf をコピーして v-host.conf をつくる

cd /etc/apache2/sites-available/
cp 000-defalut.conf v-host.conf

v-host.conf を編集して ServerName と DocumentRoot の2カ所を修正する

v-host.confの一部
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com
    ServerName v-host.domain.com

    ServerAdmin webmaster@localhost
    DocumentRoot /var/www/vhost

設定の反映

a2ensite v-host

apache2 の再起動

service apache2 reload

さくら側の設定

ドメイン管理で以下のように host の Aレコードと v-host の CNAME を設定します。さくらのマニュアルだと反映に数分かかるとのことですが、なんか瞬時に反映される感じでした

エントリ名 タイプ データ
host A host のIPアドレス
v-host CNAME host

参考URL

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2