Nginxでバーチャルホストを設定します。1台のサーバで複数のドメインを設定する方法です。設定内容は極めて単純です。serverタブを設定する分だけ増やしていけばOKです。
# vi /etc/nginx/conf.d/default.conf
# 以下を追記
# VirtualHost1
server {
listen 80;
server_name virtualhost1;
access_log /var/log/nginx/host1.access.log main;
error_log /var/log/nginx/host1.error.log;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
# VirtualHost2
server {
listen 80;
server_name virtualhost2;
access_log /var/log/nginx/host2.access.log main;
error_log /var/log/nginx/host1.error.log;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
}
|
下記コマンドでシンタックスをチェックできます。
# nginx -t nginx: the configuration file /etc/nginx/nginx.conf syntax is ok nginx: configuration file /etc/nginx/nginx.conf test is successful |
下記コマンドでNginxを再起動します。
# systemctl restart nginx |