公告:魔扣目录网为广大站长提供免费收录网站服务,提交前请做好本站友链:【 网站目录:https://www.morko.net 】, 免友链快审服务(50元/站),

点击这里在线咨询客服
新站提交
  • 网站:51998
  • 待审:31
  • 小程序:12
  • 文章:1030137
  • 会员:747

虚拟主机是一种特殊的软硬件技术,它可以将网络上的每一台计算机分成多个虚拟主机,每个虚拟主机可以独立对外提供www服务,这样就可以实现一台主机对外提供多个web服务,每个虚拟主机之间是独立的,互不影响。

nginx可以实现虚拟主机的配置,nginx支持三种类型的虚拟主机配置。

1、基于域名的虚拟主机 (server_name来区分虚拟主机——应用:外部网站)

2、基于ip的虚拟主机, (一台主机绑定多个ip地址)

3、基于端口的虚拟主机 (端口来区分虚拟主机——应用:公司内部网站,外部网站的管理后台)

基于IP

worker_processes  4;
worker_rlimit_nofile 102400;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
    
    server {
        listen       192.168.17.134:80;
        server_name  localhost;
        location / {
            root   /mcode;
            index  index.html index.htm;
        	}
        }
    
    server {
        listen      192.168.17.135:80;
        server_name  localhost;
        location / {
            root   /mcode1;
            index  index.html index.htm;
        	}
        }
}

基于端口

worker_processes  4;
worker_rlimit_nofile 102400;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
    
    server {
        listen       80;
        server_name  localhost;
        location / {
            root   /mcode;
            index  index.html index.htm;
        	}
        }
    
    server {
        listen       81;
        server_name  localhost;
        location / {
            root   /mcode1;
            index  index.html index.htm;
        	}
        }
}

基于域名

worker_processes  4;
worker_rlimit_nofile 102400;
 
events {
    worker_connections  1024;
}
 
http {
    include       mime.types;
    default_type  application/octet-stream;
    
    server {
        listen       80;
        server_name  www.mcode.com;
        location / {
            root   /mcode;
            index  index.html index.htm;
        	}
        }
    
    server {
        listen       80;
        server_name  www.mcode1.com;
        location / {
            root   /mcode1;
            index  index.html index.htm;
        	}
        }
}

分享到:
标签:三种 方式 端口 虚拟主机 配置
用户无头像

网友整理

注册时间:

网站:5 个   小程序:0 个  文章:12 篇

  • 51998

    网站

  • 12

    小程序

  • 1030137

    文章

  • 747

    会员

赶快注册账号,推广您的网站吧!
最新入驻小程序

数独大挑战2018-06-03

数独一种数学游戏,玩家需要根据9

答题星2018-06-03

您可以通过答题星轻松地创建试卷

全阶人生考试2018-06-03

各种考试题,题库,初中,高中,大学四六

运动步数有氧达人2018-06-03

记录运动步数,积累氧气值。还可偷

每日养生app2018-06-03

每日养生,天天健康

体育训练成绩评定2018-06-03

通用课目体育训练成绩评定