配置基于域名的虚拟主机
网页内容所在目录:/usr/share/nginx/html/
配置文件:/etc/nginx/conf.d/
主配置文件:/etc/nginx/nginx.conf
①创建网页内容所在目录并定义网页内容
[root@localhost ~]# cd /usr/share/nginx/html/
[root@localhost html]# mkdir test{1,2}
[root@localhost html]# ls
50x.html index.html test1 test2
[root@localhost html]# echo test1 > test1/index.html
[root@localhost html]# echo test2 > test2/index.html
②编辑配置文件
[root@localhost html]# cd /etc/nginx/conf.d/
[root@localhost conf.d]# ls
default.conf
[root@localhost conf.d]# mv default.conf{,.bak}
[root@localhost conf.d]# vim vhost.conf
添加以下内容:
server {
listen 80;
server_name www.test1.com;
location / {
root /usr/share/nginx/html/test1;
index index.html index.htm;
}
}