nginx实现虚拟主机

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 ~]#

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。