佳木斯湛栽影视文化发展公司

主頁 > 知識庫 > CentOS 7.3配置Nginx虛擬主機的方法步驟

CentOS 7.3配置Nginx虛擬主機的方法步驟

熱門標簽:百度競價點擊價格的計算公式 美圖手機 網(wǎng)站建設(shè) 使用U盤裝系統(tǒng) 智能手機 硅谷的囚徒呼叫中心 阿里云 檢查注冊表項

實驗環(huán)境

一臺最小化安裝的CentOS 7.3虛擬機

配置基本環(huán)境

1. 安裝nginx

yum install -y epel-*
yum isntall -y nginx vim

2. 建立虛機主機的站點根目錄

mkdir /var/wwwroot
mkdir /var/wwwroot/site1
mkdir /var/wwwroot/site2
echo -e "site1" >> /var/wwwroot/site1/index.html
echo -e "site2" >> /var/wwwroot/site2/index.html

3. 關(guān)閉CentOS的防火墻

setenforce 0
systemctl stop firewalld
systemctl disable firewalld

配置基于端口的虛擬主機

1. 編輯nginx配置文件

vim /etc/nginx/conf.d/vhosts.conf

2. 添加以下內(nèi)容

server {
  listen 8081;
  root /var/wwwroot/site1;
  index index.html;

  location / {
  }
}
server {
 listen 8082;
 root /var/wwwroot/site2;
 index index.html;

 location / {
 }
}

3. 啟動 nginx 服務(wù)

systemctl start nginx

4. 在宿主機訪問兩個站點

http://192.168.204.135:8081/
http://192.168.204.135:8082/

 

配置基于域名的虛擬主機

1. 重新編輯nginx配置文件

vim /etc/nginx/conf.d/vhosts.conf

2. 刪除原內(nèi)容,重新添加以下內(nèi)容

server {
  listen 80;
  server_name site1.test.com;
  root /var/wwwroot/site1;
  index index.html;

  location / {
  }
}
server {
 listen 80;
 server_name site2.test.com;
 root /var/wwwroot/site2;
 index index.html;

 location / {
 }
}

3. 重啟 nginx 服務(wù)

systemctl restart nginx

4. 在Windows上修改 hosts 文件

編輯 C:\Windows\System32\drivers\etc\hosts 文件,

添加以下內(nèi)容(根據(jù)實際情況自己修改)

192.168.204.135 site1.test.com

192.168.204.135 site2.test.com

5. 在宿主機訪問兩個站點

http://site1.test.com/
http://site2.test.com/

 

配置基于IP的虛擬主機

1. 在虛擬機增加兩個IP地址

ifconfig ens33:1 192.168.204.151
ifconfig ens33:2 192.168.204.152

2. 重新編輯nginx配置文件

vim /etc/nginx/conf.d/vhosts.conf

3. 刪除原內(nèi)容,重新添加以下內(nèi)容

server {
  listen 192.168.204.151:80;
  root /var/wwwroot/site1;
  index index.html;

  location / {
  }
}
server {
 listen 192.168.204.152:80;
 root /var/wwwroot/site2;
 index index.html;

 location / {
 }
}

4. 重啟 nginx 服務(wù)

systemctl restart nginx

5. 在宿主機訪問兩個站點

http://192.168.204.151/
http://192.168.204.152/

 

以上就是本文的全部內(nèi)容,希望對大家的學習有所幫助,也希望大家多多支持腳本之家。

標簽:懷化 湘潭 賀州 煙臺 湖北 黃山 山南 通遼

巨人網(wǎng)絡(luò)通訊聲明:本文標題《CentOS 7.3配置Nginx虛擬主機的方法步驟》,本文關(guān)鍵詞  ;如發(fā)現(xiàn)本文內(nèi)容存在版權(quán)問題,煩請?zhí)峁┫嚓P(guān)信息告之我們,我們將及時溝通與處理。本站內(nèi)容系統(tǒng)采集于網(wǎng)絡(luò),涉及言論、版權(quán)與本站無關(guān)。
  • 相關(guān)文章
  • 收縮
    • 微信客服
    • 微信二維碼
    • 電話咨詢

    • 400-1100-266
    新宾| 沁水县| 万全县| 汶上县| 隆化县| 五大连池市| 务川| 讷河市| 班戈县| 仁化县| 信宜市| 乐至县| 五莲县| 全椒县| 南充市| 阳谷县| 红桥区| 邹平县| 璧山县| 望都县| 会宁县| 巴东县| 孟连| 平遥县| 巴塘县| 金华市| 佛冈县| 丰镇市| 丰台区| 内乡县| 上思县| 兴安盟| 修文县| 肇庆市| 防城港市| 黔东| 西林县| 监利县| 德清县| 海林市| 谷城县|