码迷,mamicode.com
首页 > 其他好文 > 详细

Nginx 虚拟主机配置

时间:2017-04-15 18:02:11      阅读:230      评论:0      收藏:0      [点我收藏+]

标签:style   配置   name   nec   out   ons   ide   dex   html   

在 nginx.conf 中,一个 Server块 就是一个虚拟主机,一个虚拟主机就是一个独立的 Web站点

(1) 基于域名的虚拟主机:通过不同的域名区分不同的虚拟主机,最常用
(2) 基于端口的虚拟主机:通过不同的端口区分不同的虚拟主机
(3) 基于 IP 的虚拟主机:通过不同的 IP 区分不同的虚拟主机

技术分享
worker_processes  1;
user nobody nobody;
pid /usr/local/nginx/nginx.pid;
 
events {
    worker_connections  1024;
}
 
http {                      
    include       mime.types;                       
    default_type  application/octet-stream;         
    sendfile        on;                             
    keepalive_timeout  65;                        
    server {                                        
        listen       80;                         
        server_name  www.xxxxx.com;                   
        location / {                               
            root   html/www;                           
            index  index.html index.htm;                               
        }
    }
}     
基于域名的虚拟主机配置
技术分享
worker_processes  1;
user nobody nobody;
pid /usr/local/nginx/nginx.pid;
 
events {
    worker_connections  1024;
}
 
http {                      
    include       mime.types;                       
    default_type  application/octet-stream;         
    sendfile        on;                             
    keepalive_timeout  65;  
                      
    server {                                        
        listen       80;                         
        server_name  www.xxxxx.com;                   
        location / {                               
            root   html/www;                           
            index  index.html index.htm;                               
        }
    }

    server {                                        
        listen       80;                         
        server_name  bbs.xxxxx.com;                   
        location / {                               
            root   html/bbs;                           
            index  index.html index.htm;                               
        }
    }

    server {                                        
        listen       80;                         
        server_name  blog.xxxxx.com;                   
        location / {                               
            root   html/blog;                           
            index  index.html index.htm;                               
        }
    }
} 
基于多个域名的虚拟主机配置
技术分享
worker_processes  1;
user nobody nobody;
pid /usr/local/nginx/nginx.pid;
 
events {
    worker_connections  1024;
}
 
http {                      
    include       mime.types;                       
    default_type  application/octet-stream;         
    sendfile        on;                             
    keepalive_timeout  65;  
                      
    server {                                        
        listen       80;                         
        server_name  www.xxxxx.com;                   
        location / {                               
            root   html/www;                           
            index  index.html index.htm;                               
        }
    }

    server {                                        
        listen       81;                         
        server_name  bbs.xxxxx.com;                   
        location / {                               
            root   html/bbs;                           
            index  index.html index.htm;                               
        }
    }

    server {                                        
        listen       82;                         
        server_name  blog.xxxxx.com;                   
        location / {                               
            root   html/blog;                           
            index  index.html index.htm;                               
        }
    }
} 
基于端口的虚拟主机配置
技术分享
## 前提:要有多个网卡

worker_processes  1;
user nobody nobody;
pid /usr/local/nginx/nginx.pid;
 
events {
    worker_connections  1024;
}
 
http {                      
    include       mime.types;                       
    default_type  application/octet-stream;         
    sendfile        on;                             
    keepalive_timeout  65;  
                      
    server {                                        
        listen       192.168.1.1:80;                         
        server_name  www.xxxxx.com;                   
        location / {                               
            root   html/www;                           
            index  index.html index.htm;                               
        }
    }

    server {                                        
        listen       192.168.1.2:80;                         
        server_name  bbs.xxxxx.com;                   
        location / {                               
            root   html/bbs;                           
            index  index.html index.htm;                               
        }
    }

    server {                                        
        listen       192.168.1.3:80;                         
        server_name  blog.xxxxx.com;                   
        location / {                               
            root   html/blog;                           
            index  index.html index.htm;                               
        }
    }
} 
基于IP的虚拟主机配置

 

 

 

 

 

 

 

   

 

 

 

 

 

    

 

 

    

Nginx 虚拟主机配置

标签:style   配置   name   nec   out   ons   ide   dex   html   

原文地址:http://www.cnblogs.com/pzk7788/p/6714980.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!