濮阳杆衣贸易有限公司

主頁 > 知識庫 > 深入淺析Nginx虛擬主機

深入淺析Nginx虛擬主機

熱門標簽:地圖標注需要現(xiàn)場嗎 地圖標注企業(yè)名稱侵權案件 鶴壁電銷外呼系統(tǒng)怎么安裝 工廠位置地圖標注 企業(yè)400電話辦理哪正規(guī) 繽客網(wǎng)注冊時地圖標注出不來 網(wǎng)站上插入地圖標注內(nèi)容 400電話辦理哪家好廠商 重慶營銷外呼系統(tǒng)排名

一 虛擬主機

1.1 虛擬主機概念

 對于Nginx而言,每一個虛擬主機相當于一個在同一臺服務器中卻相互獨立的站點,從而實現(xiàn)一臺主機對外提供多個 web 服務,每個虛擬主機之間是獨立的,互不影響的。

1.2 虛擬主機類型

 通過 Nginx 可以實現(xiàn)虛擬主機的配置,Nginx 支持三種類型的虛擬主機配置:

  •  基于 IP 的虛擬主機(較少使用)
  •  基于域名的虛擬主機
  •  基于端口的虛擬主機

二 基于IP虛擬主機

2.1 配置多IP地址

 [root@nginx ~]# ifconfig eth0:0 172.24.8.70 broadcast 172.24.8.255 netmask 255.255.255.0
 [root@nginx ~]# ip addr | grep 172
 inet 172.24.8.71/24 brd 172.24.8.255 scope global noprefixroute eth0
 inet 172.24.8.72/24 brd 172.24.8.255 scope global secondary eth0:0

 提示:如上在同一臺主機添加多個IP地址。

2.2 創(chuàng)建站點目錄

 [root@nginx ~]# mkdir /usr/share/nginx/ipvhost01/
 [root@nginx ~]# mkdir /usr/share/nginx/ipvhost02/
 [root@nginx ~]# echo '<h1>Ipvhost01</h1>' > /usr/share/nginx/ipvhost01/index.html
 [root@nginx ~]# echo '<h1>Ipvhost02</h1>' > /usr/share/nginx/ipvhost02/index.html

2.3 配置虛擬主機

 [root@nginx ~]# vi /etc/nginx/conf.d/ipvhost.conf
 server {
 listen ; #監(jiān)聽端口
 server_name ipvhost.odocker.com ...; #配置虛擬主機名和IP
 location / {
 root /usr/share/nginx/ipvhost; #請求匹配路徑
 index index.html; #指定主頁
 access_log /var/log/nginx/ipvhost.access.log main;
 error_log /var/log/nginx/ipvhost.error.log warn;
 }
 }
 server {
 listen ;
 server_name ipvhost.odocker.com ...;
 location / {
 root /usr/share/nginx/ipvhost;
 index index.html;
 access_log /var/log/nginx/ipvhost.access.log main;
 error_log /var/log/nginx/ipvhost.error.log warn;
 }
 }
[root@nginx ~]# nginx -t -c /etc/nginx/nginx.conf #檢查配置文件
 [root@nginx ~]# nginx -s reload #重載配置文件

2.4 確認驗證

 瀏覽器訪問:ipvhost01.odocker.com。
 clipboard
 瀏覽器訪問:ipvhost02.odocker.com。
 clipboard

三 基于域名虛擬主機

3.1 創(chuàng)建站點目錄

 [root@nginx ~]# mkdir /usr/share/nginx/webvhost01/
 [root@nginx ~]# mkdir /usr/share/nginx/webvhost02/
 [root@nginx ~]# echo '<h1>Webvhost01</h1>' > /usr/share/nginx/webvhost01/index.html
 [root@nginx ~]# echo '<h1>Webvhost02</h1>' > /usr/share/nginx/webvhost02/index.html

3.2 配置虛擬主機

 [root@nginx ~]# vi /etc/nginx/conf.d/webvhost.conf
 server {
 listen ;
 server_name webvhost.odocker.com;
 location / {
 root /usr/share/nginx/webvhost;
 index index.html;
 access_log /var/log/nginx/webvhost.access.log main;
 error_log /var/log/nginx/webvhost.error.log warn;
 }
 }
 server {
 listen ;
 server_name webvhost.odocker.com;
 location / {
 root /usr/share/nginx/webvhost;
 index index.html;
 access_log /var/log/nginx/webvhost.access.log main;
 error_log /var/log/nginx/webvhost.error.log warn;
 }
 }
[root@nginx ~]# nginx -t -c /etc/nginx/nginx.conf #檢查配置文件
 [root@nginx ~]# nginx -s reload #重載配置文件

3.3 確認驗證

 瀏覽器訪問:webvhost01.odocker.com。
 clipboard
 瀏覽器訪問:webvhost02.odocker.com。
 clipboard

四 基于端口虛擬主機

4.1 創(chuàng)建站點目錄

[root@nginx ~]# mkdir /usr/share/nginx/portvhost01/
 [root@nginx ~]# mkdir /usr/share/nginx/portvhost02/
 [root@nginx ~]# echo '<h1>Portvhost01</h1>' > /usr/share/nginx/portvhost01/index.html
 [root@nginx ~]# echo '<h1>Portvhost01</h1>' > /usr/share/nginx/portvhost02/index.html

4.2 配置虛擬主機

 [root@nginx ~]# vi /etc/nginx/conf.d/portvhost.conf
 server {
 listen ;
 server_name portvhost.odocker.com;
 location / {
 root /usr/share/nginx/portvhost;
 index index.html;
 access_log /var/log/nginx/portvhost.access.log main;
 error_log /var/log/nginx/portvhost.error.log warn;
 }
 }
 server {
 listen ;
 server_name portvhost.odocker.com;
 location / {
 root /usr/share/nginx/portvhost;
 index index.html;
 access_log /var/log/nginx/access_portvhost.log main;
 }
 }
 [root@nginx ~]# nginx -t -c /etc/nginx/nginx.conf #檢查配置文件
 [root@nginx ~]# nginx -s reload #重載配置文件

4.3 確認驗證

 瀏覽器訪問:portvhost01.odocker.com:8080
 clipboard
 瀏覽器訪問:portvhost02.odocker.com:8081
 clipboard

到此這篇關于Nginx虛擬主機的文章就介紹到這了,更多相關Nginx虛擬主機內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!

標簽:鹽城 棗莊 渭南 克拉瑪依 常州 96 日照 東莞

巨人網(wǎng)絡通訊聲明:本文標題《深入淺析Nginx虛擬主機》,本文關鍵詞  深入,淺析,Nginx,虛擬主機,;如發(fā)現(xiàn)本文內(nèi)容存在版權問題,煩請?zhí)峁┫嚓P信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《深入淺析Nginx虛擬主機》相關的同類信息!
  • 本頁收集關于深入淺析Nginx虛擬主機的相關信息資訊供網(wǎng)民參考!
  • 推薦文章
    马山县| 云和县| 镇沅| 贵港市| 奉节县| 贺州市| 喜德县| 宁津县| 鲁甸县| 清镇市| 军事| 株洲市| 邯郸县| 木里| 常山县| 平昌县| 城固县| 沧源| 遵化市| 新巴尔虎左旗| 玛沁县| 东乌珠穆沁旗| 邳州市| 武平县| 耒阳市| 封开县| 修文县| 章丘市| 怀宁县| 怀远县| 蒙自县| 武穴市| 大厂| 祁东县| 桦南县| 镇巴县| 泸溪县| 嘉峪关市| 河间市| 瓦房店市| 新密市|