Método de configuración de host virtual Nginx

1. Enfoque basado en dominios

#第一台虚拟主机
    server {
        listen    80;
        server_name www.kgc.com;    #这里域名一定不要重复
        access_log logs/kgc.com.access.log;    #日志需求可以根据自己的要求去做,如果觉得日志无所谓分不分开大可以放到一起
        location{
            root html/kgc;        #这里是网站的根目录,注意为了测试一定要分开,里面写上不同的html
            index index.html index.htm;
        }
        ......这里省略其他代码
    }
#第二台虚拟主机
    server{
        listen 80;
        server_name www.accp.com;
        access_log logs/accp.com.access.log;
        location{
            root    html/accp;
            index index.html index.htm;
        }
        ......这里省略其他代码
    }

2. Enfoque basado en puertos

#第一台虚拟主机
server {
    listen 8000;
    server_name www.kgc.xyz;
    access_log logs/kgc.com.access.log;
    location{
        root html/kgc;
        index index.html index.htm;
    }
......省略其他代码
}
#第二台虚拟主机
server{
    listen 8001;
    server_name www.kgc.xyz;
    access_log logs/accp.access.log;
    location{
        root html/accp;
        index index.html index.htm;
    }
......省略其他代码
}

3. Según la dirección IP

#第一台虚拟主机
server {
    listen 192.168.52.11:80;
    server_name www.kgc.com;    //域名IP都可以
    access_log logs/kgc.com.access.log;
    location{
        root html/kgc;
        index index.html index.htm;
    }
......省略其他代码
}
#第二台虚拟主机
server{
    listen 192.168.52.12:80;
    server_name ww.kgc.com;    //域名IP都可以
    access_log logs/accp.com.access.log;
    location{
        root html/accp;
        index index.html index.htm;
    }
......省略其他代码
}

Supongo que te gusta

Origin blog.csdn.net/weixin_45647891/article/details/110927664
Recomendado
Clasificación