nginx基于域名的虛擬主機 虛擬機安裝nginx



文章插圖
nginx基于域名的虛擬主機 虛擬機安裝nginx

文章插圖
五 虛擬主機
1 虛擬主機介紹
就是把一臺物理服務器劃分成多個“虛擬”的服務器,每一個虛擬主機都可以有獨立的域名和獨立的目錄
同時發布兩個網站:
DocumentRoot /usr/local/nginx/html/web1
DocumentRoot /usr/local/nginx/html/web2
2 基于IP的虛擬主機
應用場景:IP充足的環境
server {listen192.168.11.251:80;location / {roothtml/web1;index index.html index.htm index.php;}}server {listen192.168.11.252:80;location / {roothtml/web2;index index.html index.htm;}}基于IP的虛擬主機特點
不同IP對應不同網站
訪問方便,用戶直接使用默認端口即可訪問
服務器需要有多個IP地址(一個公網IP大概一年的費用是600左右)
維護方便,基于獨立IP的站點,便于監控、維護 。
3 基于端口的虛擬主機
#只需要一個IP
#缺點 端口你是無法告訴公網用戶 無法適用于公網客戶 適合內部用戶
基于端口server {listen80;#server_namewww.abc.com;location / {roothtml/web1;index index.html index.htm index.php;}}server {listen8080;#server_namewww.abc.com;location / {roothtml/web2;index index.html index.htm;}}基于端口的虛擬主機特點
不同端口對應不同網站
訪問需要加端口
節省IP地址
適合私網運行
4 基于域名的虛擬主機
#一個網站必然有一個域名
基于域名server {listen80;server_name web1.a.com;location / {roothtml/web1;index index.html index.htm index.php;}}server {listen80;server_name web2.b.com;location / {roothtml/web2;index index.html index.htm;}}基于域名的虛擬主機特點
不同域名對應不同網站
需要多個域名 可以是二級或三級域名
每個站點使用默認端口,方便用戶訪問
只需要一個IP地址,節約成本
適合公網環境
總結
什么是虛擬主機
虛擬主機的作用
虛擬主機如何實現
重點:不同類型虛擬主機的作用,如何實現
難點:虛擬主機實現的形式
【nginx基于域名的虛擬主機 虛擬機安裝nginx】3分鐘了解計算機發展歷史-組團學