
最初に、以下にアクセスするときに正しく動作する conf ファイルを作成しましたhttp://www.domain.com
。
server {
listen 80;
listen [::]:80;
root /var/www/domain;
index index.html
server_name domain.com www.domain.com;
}
次に、サブドメイン用に別の conf ファイルを作成することにしました。
server {
listen 80;
listen [::]:80;
root /var/www/subdomain.domain;
index index.html
server_name subdomain.domain.com;
}
http://www.domain.com
ここで問題となるのは、またはにアクセスするたびにhttp://subdomain.domain.com
、どちらの場合も、結果はサブドメインで取得する必要があるページになるということです。
新しい conf ファイルがsite-enabled
フォルダーに正しく追加されました:
ln -s /etc/nginx/site-available/subdomain.domain.conf /etc/nginx/site-enabled/subdomain.domain.conf
私の DNS レコードは次のようになります。
domain.com. IN A <server_ip>
www.domain.com. IN A <server_ip>
subdomain.domain.com. IN A <server_ip>
答え1
;
ディレクティブに が欠落しているindex
ため、nginxは次のように解釈します。
index.html
server_name domain.com www.domain.com;
ディレクティブの内容としてindex
。したがって、 で定義された仮想ホストはなくserver_name
、nginx はサブドメインの仮想ホストをキャッチオール仮想ホストとして使用します。