ITPub博客

首页 > > > nignx从入门到精通-虚拟主机

nignx从入门到精通-虚拟主机

作者:zhmw 时间:2019-12-04 15:34:43 0 删除 编辑

虚拟主机

基于IP的虚拟主机

基于port的虚拟主机

基于域名的虚拟主机

一、虚拟主机介绍

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

同时发布两个网站:

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

location / {

root html/web1;

index index.html index.htm index.php;

}

}

server {

listen 8080;

#server_name

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地址,节约成本

适合公网环境

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/69901620/viewspace-3156627/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2018-12-04

  • 博文量
    295
  • 访问量
    9529