Nginx 虚拟主机
生活随笔
收集整理的這篇文章主要介紹了
Nginx 虚拟主机
小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.
一、虛擬主機介紹
就是把一臺物理服務器劃分成多個“虛擬”的服務器,每一個虛擬主機都可以有獨立的域名和獨立的目錄
同時發(fā)布兩個網(wǎng)站:
DocumentRoot /usr/local/nginx/html/web1
DocumentRoot /usr/local/nginx/html/web2
二、基于IP的虛擬主機
應用場景:IP充足的環(huán)境
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對應不同網(wǎng)站
訪問方便,用戶直接使用默認端口即可訪問
服務器需要有多個IP地址(一個公網(wǎng)IP大概一年的費用是600左右)
維護方便,基于獨立IP的站點,便于監(jiān)控、維護。
三、基于端口的虛擬主機
只需要一個IP
缺點:端口你是無法告訴公網(wǎng)用戶 無法適用于公網(wǎng)客戶 適合內部用戶。
基于端口 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;} }基于端口的虛擬主機特點
不同端口對應不同網(wǎng)站
訪問需要加端口
節(jié)省IP地址
適合私網(wǎng)運行
四、基于域名的虛擬主機
一個網(wǎng)站必然有一個域名
基于域名 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;} }基于域名的虛擬主機特點
不同域名對應不同網(wǎng)站
需要多個域名 可以是二級或三級域名
每個站點使用默認端口,方便用戶訪問
只需要一個IP地址,節(jié)約成本
適合公網(wǎng)環(huán)境
總結
以上是生活随笔為你收集整理的Nginx 虚拟主机的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Nginx 应用
- 下一篇: Nginx 下载限速