LoginSignup
2
1

More than 5 years have passed since last update.

GCEでサブドメインを使ってWEBページを公開するときの設定

Posted at

環境:

  • Debian9 (GCE)
  • nginx/1.14.0

example.comを持っていて、sample.example.comを追加することにする

公開するページのファイルを配置

/var/www/sample/に置くことにする

nginxの設定ファイルに公開するページの設定を書く

nignxは/etc/nginx/sites-available/sample.confなどの名前で設定を置き、/etc/nginx/sites-enabled/以下にそのシンボリックリンクを作成するやり方がある。
/etc/nginx/nginx.conf

include /etc/nginx/sites-enabled/*.conf;

と書けば設定を読み込んでくれる。
編集するときはsites-available/の方を編集して、要らなくなったらsites-enabled/の方を消せば良い(また必要になったらシンボリックリンクを貼り直す)

sudo vi /etc/nginx/sites-available/sample.conf

server {
  listen 80;
  server_name sample.example.com;
  root /var/www/sample;
  location /{
    index index.html;
  }
  server_tokens off;
}

シンボリックリンク作成
sudo ln -s /etc/nginx/sites-available/sample.conf /etc/nginx/sites-enabled/sample.conf

再起動
sudo service nginx restart

サブドメインをGCEのCloudDNSに登録する

GCEのダッシュボード左上のマークを押して、「ネットワークサービス」>「Cloud DNS」を選択
ゾーンを選択
[レコードセットを追加]ボタンから

DNS名
sample.example.com
IPv4アドレス
当該インスタンスの外部IP
を入力して
[作成]を押す

参考:

Nginxでサブドメインを同じIPアドレスで処理

2
1
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
2
1