1、创建一个目录用于存放虚拟站点的配置文件
[root@localhost ~]# mkdir -p /software/nginx/conf/conf.d/
2、修改主配置文件/software/nginx/conf/nginx.conf,将刚创建的目录中的*.conf文件包含进来
[root@localhost conf]# vi nginx.conf
在配置文件的倒数第二行插入
include /software/nginx/conf/conf.d/*.conf;
3、在/software/nginx/conf/conf.d/目录下,创建第一个虚拟站点abc.cn的配置文件
[root@localhost conf.d]# vi abc.conf
server {
listen 80;
server_name www.abc.cn;
location / {
root /data/nginx/html/abc;
}
}
4、在/software/nginx/conf/conf.d/目录下,创建第二个虚拟站点uhn.cn的配置文件
[root@localhost conf.d]# vi uhn.conf
server {
listen 80;
server_name www.uhn.cn;
location / {
root /data/nginx/html/uhn;
}
}
5、在/data/nginx/html/abc 和 /data/nginx/html/uhn下创建测试网页
[root@localhost html]# pwd
/data/nginx/html
[root@localhost html]# tree
.
├── abc
│ └── index.html
└── uhn
└── index.html
6、重启nginx服务
[root@localhost html]# nginx -s reload
7、使用浏览器访问测试正常