LoginSignup
4
3

More than 5 years have passed since last update.

[sakura vps] さくらのvps(nginx)でサブドメインを設定する

Posted at

概要

さくらのvps(nginx)でサブドメインを設定する方法です。


hogehoge.com
stagint.hogehoge.com

ネームサーバーにドメインを設定

  1. 下記のURLへアクセスする
    https://secure.sakura.ad.jp/menu/dns/

  2. 「ゾーンの設定」をクリックする

  3. 「変更」をクリックする

  4. 下記の項目を追加する

用語 記述
エントリ名 staging
種別 別名(CNAME)
@
DNSチェック する
TTLの指定 なし
  1. 上記項目を追加したら「新規登録」をクリックする

サーバーのバーチャルホストを追加

  1. SFTPで「/etc/nginx/conf.d/」にアクセスします。
  2. 「default.conf」をダウンロードし、ファイル名を「stagint.hogehoge.com.conf」へ変更します。
  3. ファイルを開き、内容を下記のように変更します。
server {
  server_name stagint.hogehoge.com;
  location / {
    root   /usr/share/nginx/html/staging;
    index  index.php index.html index.htm;
  }
}
  1. ファイルをアップロードします。
  2. ターミナルからサーバーへログインし、下記のコマンドを入力しサーバーを再起動します。
$ sudo nginx -s reload

まとめ

ネームサーバーにドメインを設定し、サーバーのバーチャルホストを追加、再起動することでサブドメインを設定できます。

おそらく役立つ情報

痒いところに手が届くかもしれない記事を書いています。
フォローしてくれるとやる気になります!

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