校园春色亚洲色图_亚洲视频分类_中文字幕精品一区二区精品_麻豆一区区三区四区产品精品蜜桃

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

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

熱門標簽:百應電銷機器人靠譜嗎 申請400電話號碼多少錢 coreldraw地圖標注 營銷電銷機器人招商 信陽銷售外呼系統招商 如何在各種地圖標注自己的地址 物超所值的400電話申請 遼寧電銷平臺外呼系統軟件 菏澤crm外呼系統價格

實驗環境

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

配置基本環境

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. 關閉CentOS的防火墻

setenforce 0
systemctl stop firewalld
systemctl disable firewalld

配置基于端口的虛擬主機

1. 編輯nginx配置文件

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

2. 添加以下內容

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

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

 location / {
 }
}

3. 啟動 nginx 服務

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. 刪除原內容,重新添加以下內容

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 服務

systemctl restart nginx

4. 在Windows上修改 hosts 文件

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

添加以下內容(根據實際情況自己修改)

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. 刪除原內容,重新添加以下內容

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 服務

systemctl restart nginx

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

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

 

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

標簽:瀘州 內江 湖北 江西 廈門 江門 泰安 玉樹

巨人網絡通訊聲明:本文標題《CentOS 7.3配置Nginx虛擬主機的方法步驟》,本文關鍵詞  CentOS,7.3,配置,Nginx,虛擬主機,;如發現本文內容存在版權問題,煩請提供相關信息告之我們,我們將及時溝通與處理。本站內容系統采集于網絡,涉及言論、版權與本站無關。
  • 相關文章
  • 下面列出與本文章《CentOS 7.3配置Nginx虛擬主機的方法步驟》相關的同類信息!
  • 本頁收集關于CentOS 7.3配置Nginx虛擬主機的方法步驟的相關信息資訊供網民參考!
  • 推薦文章
    主站蜘蛛池模板: 伊春市| 沈丘县| 玛纳斯县| 邹平县| 兰溪市| 奉节县| 黑河市| 平谷区| 辉县市| 五华县| 德昌县| 浦城县| 定远县| 富锦市| 昭平县| 方山县| 玉溪市| 鸡西市| 通渭县| 海宁市| 白沙| 齐齐哈尔市| 凤冈县| 西丰县| 梁平县| 洛宁县| 永春县| 安远县| 文水县| 于田县| 黄陵县| 六枝特区| 志丹县| 黄浦区| 丹巴县| 崇仁县| 镇巴县| 奎屯市| 南昌县| 伊宁市| 麦盖提县|