linux - centos下配置虚拟主机

1.root账号进入终端,ifconfig查看当前ip地址信息和网卡

2.重新配置eth0网卡

ifconfig eth0 192.168.1.9 netmask 255.255.255.0

3.开始配置第一个虚拟主机(broadcast必须与eth0的一致)

ifconfig eth0:1 192.168.1.7 broadcast 192.168.1.255 netmask 255.255.255.0

4.配置第二个虚拟主机

ifconfig eth0:1 192.168.1.8 broadcast 192.168.1.255 netmask 255.255.255.0

5.其他虚拟主机配置参考以上

 

6.开始配置nginx文件

cd /usr/local/nginx/conf

touch virtual-host.conf

vim virtual-host.conf
user nobody;
worker_processes 4;
events {
        worker_connections 1024;
}
http {
        server {
                listen 192.168.1.7:80;
                server_name 192.168.1.7;
                access_log logs/server1.access.log combined;
                location / {
                        index index.html index.htm;
                        root html/server1;
                }
        }
        server {
                listen 192.168.1.8:80;
                server_name 192.168.1.8;
                access_log logs/server2.access.log combined;
                location / {
                        index index.html index.htm;
                        root html/server2;
                }
        }
}

7.在/usr/local/nginx/html下新建server1和server2目录,并分别在目录里新建index.html文件

8.加载virtual-host.conf配置文件

/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/virtual-host.conf

9.在浏览器里访问相应地址 - 192.168.1.7 or 192.168.1.8

 

10.如有需要,结束nginx服务

pkill -9 nginx

 

posted @ 2018-03-08 15:48  sunbey80  阅读(1195)  评论(0编辑  收藏  举报