zoukankan      html  css  js  c++  java
  • nginx虚拟主机

    一、虚拟主机介绍

    就是把一台物理服务器划分成多个“虚拟”的服务器,每一个虚拟主机都可以有独立的域名和独立的目录

    同时发布两个网站:

    DocumentRoot /usr/local/nginx/html/web1

    DocumentRoot /usr/local/nginx/html/web2

    二、基于IP的虚拟主机

    应用场景:IP充足的环境

    server {
        listen       192.168.11.251:80;
        location / {
            root   html/web1;
            index  index.html index.htm index.php;
        }
    }
    server {
        listen       192.168.11.252:80;
    location / {
            root   html/web2;
            index  index.html index.htm;
        }
    }

    基于IP的虚拟主机特点

    • 不同IP对应不同网站
    • 访问方便,用户直接使用默认端口即可访问
    • 服务器需要有多个IP地址(一个公网IP大概一年的费用是600左右)
    • 维护方便,基于独立IP的站点,便于监控、维护。

    三、基于端口的虚拟主机

    #只需要一个IP

    #缺点 端口你是无法告诉公网用户 无法适用于公网客户 适合内部用户

    基于端口
    server {
        listen       80;
        #server_name  www.abc.com;
        location / {
            root   html/web1;
            index  index.html index.htm index.php;
        }
    }
    server {
        listen       8080;
        #server_name  www.abc.com;
        location / {
            root   html/web2;
            index  index.html index.htm;
        }
    }

    基于端口的虚拟主机特点

    • 不同端口对应不同网站
    • 访问需要加端口
    • 节省IP地址
    • 适合私网运行

    四、基于域名的虚拟主机

    #一个网站必然有一个域名

    基于域名
    server {
        listen       80;
        server_name  web1.ayitula.com;
        location / {
            root   html/web1;
            index  index.html index.htm index.php;
        }
    }
    server {
        listen       80;
        server_name  web2.ayitula.com;
        location / {
            root   html/web2;
            index  index.html index.htm;
        }
    }

    基于域名的虚拟主机特点

    • 不同域名对应不同网站
    • 需要多个域名 可以是二级或三级域名
    • 每个站点使用默认端口,方便用户访问
    • 只需要一个IP地址,节约成本
    • 适合公网环境
  • 相关阅读:
    day46 mysql进阶
    解决:ping github.com遇到“请求超时”
    修改hosts文件
    Python正课135 —— 基础扩展1
    Python正课136 —— 基础扩展2
    05 树莓派安装Python3.6
    一次可以面向百度的笔试
    作业23
    获取类名和方法名
    面向对象三大特性之继承
  • 原文地址:https://www.cnblogs.com/wenyule/p/12887085.html
Copyright © 2011-2022 走看看