VPSで複数ドメインを設定 - VisualHost

基本的にルートでやります。

サイトのファイルを置くディレクトリを作成。-pオプションで再帰

$ mkdir -p /var/www/totz-yuta.com/public_html

自分の作業用ユーザに権限をあげる。

$ sudo chown -R totz:totz /var/www/totz-yuta.com/public_html

以下を/etc/httpd/conf.d/totz-yuta.com.confに記述。拡張子が.confなら名前はなんでもいいらしい

<VirtualHost *:80>
        ServerName totz-yuta.com
        DocumentRoot "/var/www/totz-yuta.com/public_html"
        DirectoryIndex index.html index.php
        ErrorLog /var/log/httpd/totz-yuta.com_error_log
        CustomLog /var/log/httpd/totz-yuta.com_access_log combined
        AddDefaultCharset UTF-8
        <Directory "/var/www/totz-yuta.com/public_html">
                AllowOverride All
        </Directory>
</VirtualHost>

次に/etc/httpd/conf/httpd.confをの以下を編集

#
# Use name-based virtual hosting.
#
NameVirtualHost *:80    # ここのコメントアウトを外す
#
# NOTE: NameVirtualHost cannot be used without a port specifier
# (e.g. :80) if mod_ssl is being used, due to the nature of the
# SSL protocol.
#

以下でサーバーをrestart。エラーが出てたらこれで分かる。

$ /etc/rc.d/init.d/httpd restart

GMOのRailパックみたいなよくわからないVPSのプランを契約してしまってそのファイルがすごく邪魔で苦労した...。結局/etc/httpd/conf.d/passenger.confの名前を変更するという強行で解決)

VPS側でドメイン追加の設定と、ドメインを取得したところでDNSネームサーバの設定をします。会社によって異なるのでここでは省略。

僕はちょうどGMOムームードメインだったので以下のサイトを参考にさせていただきました。

GMOクラウドのVPSに独自ドメインを追加 - VPS比較 - Webkaru

ここでIPアドレスをいれればネームサーバを確認できる。

ANSI Whois Gateway: ドメイン名 / IPアドレス検索サービス

僕の場合は3時間ほどで更新されました!多分そのときどきによりますがかなり早く開通した!やったーー