LoginSignup
4
6

More than 5 years have passed since last update.

[*Apache*] さくらVPSでバーチャルホストの設定

Posted at

はじめに

1つのサーバーで複数のドメインを設定したいときの設定メモ。

環境

  • サーバー: さくらVPS
  • OS: CentOS7
  • Apache: 2.4.6
  • ドメイン: ムームードメイン

手順

Apacheインストール・設定

$ yum install -y httpd

インストールできたら起動。

$ systemctl start httpd.service

ステータスをチェック。

$ systemctl status httpd
# activeになっていることを確認

自動起動の設定。

$ systemctl enable httpd.service

設定が効いてるか確認。

$ systemctl list-unit-files | grep httpd
# httpd.service     enabled

ドメイン取得・設定

今回はムームードメインで取得。
取得後、ドメイン一覧 > 設定したいドメインを選択 > ネームサーバ設定変更で、GMOペパボ以外 のネームサーバを使用するを選択し、以下を設定。

ネームサーバー 設定値
ネームサーバー1 ns1.dns.ne.jp
ネームサーバー2 ns2.dns.ne.jp

さくらVPS側の設定

ネームサーバ登録画面から、新しいネームサーバを登録する。
スクリーンショット 2016-03-13 21.45.37.png

ゾーン編集をクリックする。
スクリーンショット 2016-03-13 22.07.24.png

変更ボタンをクリックする。
スクリーンショット 2016-03-13 22.08.14.png

以下を新規登録。
スクリーンショット 2016-03-13 22.09.18.png

データ送信を忘れずにクリック。
スクリーンショット 2016-03-13 22.11.10.png

・・・この設定を使いたいドメインの数分やる。

Apacheの設定

以下のファイルを作成。(ファイル名は拡張子さえあってれば何でも良い)

$ vim /etc/httpd/conf.d/vhost.conf

中身はドメインごとに複数用意。(以下は例としてexample.comexample.jpを使用)

<VirtualHost *:80>
DocumentRoot /var/www/html/example.com
ServerName www.example.com
ServerAlias example.com
CustomLog logs/example.com-access.log common
ErrorLog  logs/example.com-error.log
AddDefaultCharset UTF-8
<Directory "/var/www/html/example.com/">
AllowOverride All
</Directory>
</VirtualHost>


<VirtualHost *:80>
DocumentRoot /var/www/html/example.jp
ServerName www.example.jp
ServerAlias example.jp
CustomLog logs/example.jp-access.log common
ErrorLog  logs/example.jp-error.log
AddDefaultCharset UTF-8
<Directory "/var/www/html/example.jp/">
AllowOverride All
</Directory>
</VirtualHost>

再起動。(設定ファイルの再読み込みでもいけるらしい)

$ systemctl restart httpd

参考

4
6
0

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
4
6