LoginSignup
3
5

More than 3 years have passed since last update.

Nginxでサブドメインとバーチャルホスト設定

Last updated at Posted at 2020-09-29

Nginxでサブドメインとバーチャルホストを作成する方法になります。
今回の以下の構成で。

ドメイン ディレクトリ
https://domain-name.com /usr/share/nginx/html
https://sub.domain-name.com /usr/share/nginx/html/sub

/etc/nginx/conf.d/virtualhost.conf を作成します。

/etc/nginx/conf.d/virtualhost.conf
server {
    listen 80;
    server_name sub.domain-name.com;
    root /usr/share/nginx/html/sub;

    location / {
      index index.html;
    }
}
server {
    listen 80;
    server_name domain-name.com;
    root /usr/share/nginx/html;
}

サブドメインが付かないもの最低限の設定にしています。
まず/etc/nginx/nginx.confから読み込まれるので、そこを最低限邪魔しないようにしてます。

※AWSのEC2+ELB+Route53でも同様の構成で動作検証を行いました。

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