Ninx虚拟主机的配置

1、配置ip
ifconfig eth0 192.168.1.7 netmask 255.255.255.0
ifconfig eth0 192.168.1.17 netmak 255.255.255.0

2、配置conf文件
/usr/local/nginx/conf/xnzj.conf

user nobody;
worker_processes 4;
events{
    work_connections 1024;
}

http{
    
    #virtual1
    server{
        listen 192.168.1.9:80;
        server_name 192.168.1.9;
        access_log logs/server1.access.log combined; #默认的
        location / {
            index index.html index.htm;
            root html/server1; #/usr/local/nginx/html/server1
        }
    }

    #virtual2
    server{
        listen 192.168.1.17:80;
        server_name 192.168.1.17;
        access_log logs/server2.access.log combined; #默认的
        location / {
            index index.html index.htm;
            root html/server2; #/usr/local/nginx/html/server2
        }
    }
}

3、启动虚拟主机
/usr/local/nginx/sbin/nginx -c /usr/local/nginx/conf/xnzj.conf

直接在浏览器访问虚拟地址ip即可,不过前提是在对应的虚拟目录下已经建好了被访问的文件。

如:index.html

posted @ 2016-02-29 17:10  北京流浪儿  阅读(417)  评论(0编辑  收藏  举报