zoukankan      html  css  js  c++  java
  • 第七章 Nginx配置虚拟主机

    一、配置方式

    #虚拟主机配置方式:
    1.基于多IP的方式
    2.基于多端口的方式
    3.基于多域名的方式
    

    二、基于多IP的方式

    1.第一个配置文件
    [root@web02 /etc/nginx/conf.d]# vim mali.conf 
    server {
        listen 10.0.0.8:80;
        server_name localhost;
        location / {
            root /code/zhiwu;
            index index.html;
        }
    }
    
    2.第二个配置文件
    [root@web02 /etc/nginx/conf.d]# vim tank.conf 
    server {
        listen 172.16.1.8:80;
        server_name localhost;
        location / {
            root /code/tank;
            index index.html;
        }
    }
    
    3.检查配置重启
    [root@web02 /etc/nginx/conf.d]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    
    [root@web02 /etc/nginx/conf.d]# systemctl restart nginx
    

    三、基于多端口的方式

    1.第一个配置
    [root@web02 /etc/nginx/conf.d]# cat mali.conf 
    server {
        listen 80;
        server_name localhost;
        location / {
            root /code/zhiwu;
            index index.html;
        }
    }
    
    2.第二个配置
    [root@web02 /etc/nginx/conf.d]# cat tank.conf 
    server {
        listen 81;
        server_name localhost;
        location / {
            root /code/tank;
            index index.html;
        }
    }
    
    3.检查配置并重启
    [root@web02 /etc/nginx/conf.d]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    
    [root@web02 /etc/nginx/conf.d]# systemctl restart nginx
    
    4.访问测试
    1)访问 http://10.0.0.8:80
    2)访问 http://10.0.0.8:81
    

    四、基于多域名的方式

    1.第一个配置
    [root@web02 /etc/nginx/conf.d]# vim mali.conf 
    server {
        listen 80;
        server_name www.mali.com;
        location / {
            root /code/zhiwu;
            index index.html;
        }
    }
    
    2.第二个配置
    [root@web02 /etc/nginx/conf.d]# vim tank.conf 
    server {
        listen 80;
        server_name www.tank.com;
        location / {
            root /code/tank;
            index index.html;
        }
    }
    3.检查并重启
    [root@web03 /etc/nginx/conf.d]# nginx -t
    nginx: the configuration file /etc/nginx/nginx.conf syntax is ok
    nginx: configuration file /etc/nginx/nginx.conf test is successful
    
    [root@web03 /etc/nginx/conf.d]# systemctl restart nginx
    
    4.配置本地hosts
    C:\Windows\System32\drivers\etc\hosts
    10.0.0.8 www.mali.com
    10.0.0.8 www.tank.com
    
    5.访问测试
    
  • 相关阅读:
    Array 对象-sort()
    vue安装
    前端面试题
    JavaScript对象原型
    CSS如何水平垂直居中?
    块格式化上下文(Block Formatting Context,BFC)
    盒子模型
    前端基础
    Markdown语法
    浏览器 滚动条 占据 y轴宽度的解决方案
  • 原文地址:https://www.cnblogs.com/jhno1/p/13597241.html
Copyright © 2011-2022 走看看