4
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

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でも同様の構成で動作検証を行いました。

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?