nginx虚拟主机配置---构建2个域名的虚拟主机

虚拟主机:

1.基于ip地址 IP-based–》一个域名对应一个ip
2.基于域名(name-based) --》所有的域名使用同一个ip --》使用非常多的

1.修改nginx.conf

打开nginx域名配置文件存放路径

cd /usr/local/nginx/conf

编辑配置文件

[root@localhost conf]#vim  nginx.conf 在配置文件里添加2个server块,对应2个不同的域名 --》加到http块
    server {
        listen       80;
        server_name  www.sc.com  ;

        location / {
            root   html/sc.com;   ---》需要在html目录下新建sc.com,并且在里面还要新建首页index.html,内容自己定义
            index  index.html index.htm;
        }
    }

    server {
        listen       80;
        server_name  www.xxue.com;

        location / {
            root   html/xxue.com;         ---》需要在html目录下新建feng.com,并且在里面还要新建首页index.html,内容自己定义
            index  index.html index.htm;
        }
    }

2.新建存放网页的文件夹和首页

[root@localhost html]# pwd
/usr/local/scnginx8/html
[root@localhost html]# 
[root@localhost scnginx8]# tree html/xxue.com/
html/xxue.com/
└── index.html  --》内容是xxue.com

0 directories, 1 file
[root@localhost scnginx8]# tree html/sc.com/
html/sc.com/
└── index.html  --》内容是sc.com

0 directories, 1 file

3.启动nginx

[root@localhost scnginx8]# nginx -t
nginx: the configuration file /usr/local/scnginx8/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/scnginx8/conf/nginx.conf test is successful
[root@localhost scnginx8]# nginx -s reload

4.测试

4.1在客户机上需要修改hosts文件,在里面添加

	www.sc.com  192.168.66.2
	www.xxue.com  192.168.66.2

4.2 在浏览器里访问域名 http://www.sc.com 或者http://www.xxue.com 会看到不同内容

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值