zoukankan      html  css  js  c++  java
  • nginx 的三种虚拟主机配置方法



    nginx三种虚拟主机配置的方法.


    基于端口


    在生产环境中一般使用端口或者域名。

    [root@web01 /etc/nginx/conf.d]# cat web01.conf 
    server {
    	listen 80;
    	server_name 10.0.0.7;
    
    	location / {
    		root /code/web01;
    		index index.html;
    }
    }
    [root@web01 /etc/nginx/conf.d]# cat web02.conf 
    server {
            listen 81;
            server_name 10.0.0.7;
    
            location / {
                    root /code/web02;
                    index index.html;
    }
    }
    
    [root@web01 /etc/nginx/conf.d]# cat web03.conf 
    server {
            listen 82;
            server_name 10.0.0.7;
    
            location / {
                    root /code/web03;
                    index index.html;
    }
    }
    

    基于域名


    [root@web01 /etc/nginx/conf.d]# cat web01.conf 
    server {
    	listen 80;
    	server_name www.web01.com;
    
    	location / {
    		root /code/web01;
    		index index.html;
    }
    }
    [root@web01 /etc/nginx/conf.d]# cat web02.conf 
    server {
            listen 80;
            server_name www.web02.com;
    
            location / {
                    root /code/web02;
                    index index.html;
    }
    }
    
    [root@web01 /etc/nginx/conf.d]# cat web03.conf 
    server {
            listen 80;
            server_name www.web03.com;
    
            location / {
                    root /code/web03;
                    index index.html;
    }
    }
    
    

    基于IP


    很少使用,保持域名和端口一样。

    就两个解决方案:

    1. 添加物理网卡

    实际上物理端口通常只有4个,当主机上面有10台虚拟站点的时候使用添加物理网卡单独配置IP来实现nginx虚拟主机就不适用了。

    1. 给一块网卡添加多个ip,虚拟IP
    # 1.绑定IP给eth0
    [root@web01 /etc/nginx/conf.d]# ifconfig eth0:0 10.0.0.100/24
    [root@web01 /etc/nginx/conf.d]# ifconfig eth0:1 10.0.0.101/24
    
    # 2、配置文件
    [root@web01 /etc/nginx/conf.d]# cat web01.conf 
    server {
    	listen 80;
    	server_name 10.0.0.7;
    
    	location / {
    		root /code/web01;
    		index index.html;
    }
    }
    [root@web01 /etc/nginx/conf.d]# cat web02.conf 
    server {
            listen 80;
            server_name 10.0.0.100;
    
            location / {
                    root /code/web02;
                    index index.html;
    }
    }
    
    [root@web01 /etc/nginx/conf.d]# cat web03.conf 
    server {
            listen 80;
            server_name 10.0.0.101;
    
            location / {
                    root /code/web03;
                    index index.html;
    }
    }
    


    FBI WARNING

    QQ:1402122292 认准原创sheldon 别人叫我晓东
  • 相关阅读:
    关于jquery
    3D转换(位置)+过渡+透视
    浅谈相对定位与绝对定位
    多层菜单
    菜单栏
    轮播图
    jsp中表格序号递增,varStatus="vs"
    关于数据库的增删改查
    put请求(单整体改),patch请求(群单改,群改)
    ModelSerializer 序列化和反序列化,及序列化整合,单删/增,群删/增(delete请求)
  • 原文地址:https://www.cnblogs.com/gshelldon/p/13301036.html
Copyright © 2011-2022 走看看