欢迎来到站长天空!

其它服务器

当前位置: 主页 > 服务器 > 其它服务器

Nginx系列:虚拟主机配置(IP、端口、域名)三种配置方式

时间:2025-12-10 04:30:05|栏目:其它服务器|点击:

虚拟主机是一种特殊的软硬件技术,它可以将网络上的每一台计算机分成多个虚拟主机,每个虚拟主机可以独立对外提供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;
        	}
        }
}

上一篇:Nginx系列:详解进程结构和热部署

栏    目:其它服务器

下一篇:Nginx系列:简介和安装(基于yum和源码的方式)

本文标题:Nginx系列:虚拟主机配置(IP、端口、域名)三种配置方式

本文地址:https://zz.feitang.co/server/29773.html

广告投放 | 联系我们 | 版权申明

申明:本站所有的文章、图片、评论等,均由网友发表或上传并维护或收集自网络,属个人行为,与本站立场无关。

如果侵犯了您的权利,请与我们联系,我们将在24小时内进行处理、任何非本站因素导致的法律后果,本站均不负任何责任。

联系QQ:257218569 | 邮箱:257218569@qq.com

Copyright © 2018-2025 站长天空 版权所有 Powered by EyouCms冀ICP备14023439号