1) yum安装nginx,创建站点页面
[root@centos ~]#yum install nginx -y
[root@centos ~]#mkdir /data/test1
[root@centos ~]#mkdir /data/test2
[root@centos ~]#echo "welcome to test1" > /data/test1/index.html
[root@centos ~]#echo "welcome to test2" > /data/test2/index.html
2)修改配置文件,在 /etc/nginx/conf.d/ 下面添加以子配置文件 test.conf
[root@centos ~]#vim /etc/nginx/conf.d/test.conf
server_tokens off; 不显示nginx的版本号
server {
server_name www.xingyu.com;
root /data/test1;
}
server {
server_name www.xingyu.vip;
root /data/test2;
}
3)找一个测试机,修改 /etc/hosts 文件
[root@test~]#vim /etc/hosts
192.168.9.100 www.xingyu.com www.xingyu.vip
4)启动 nginx 服务, 测试
启动
[root@centos ~]#nginx
测试
[root@test ~]#curl www.xingyu.com
welcome to test1
[root@test ~]#curl www.xingyu.vip
welcome to test2
[root@test ~]#