国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 網站 > Nginx > 正文

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

2024-08-30 12:30:13
字體:
來源:轉載
供稿:網友

實驗環境

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

配置基本環境

1. 安裝nginx

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

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

mkdir /var/wwwrootmkdir /var/wwwroot/site1mkdir /var/wwwroot/site2echo -e "site1" >> /var/wwwroot/site1/index.htmlecho -e "site2" >> /var/wwwroot/site2/index.html

CentOS7.3,Nginx,虛擬主機

3. 關閉CentOS的防火墻

setenforce 0systemctl stop firewalldsystemctl disable firewalld

CentOS7.3,Nginx,虛擬主機

配置基于端口的虛擬主機

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 / { }}

CentOS7.3,Nginx,虛擬主機

3. 啟動 nginx 服務

systemctl start nginx

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

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

CentOS7.3,Nginx,虛擬主機

CentOS7.3,Nginx,虛擬主機

配置基于域名的虛擬主機

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 / { }}

CentOS7.3,Nginx,虛擬主機

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

CentOS7.3,Nginx,虛擬主機

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

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

CentOS7.3,Nginx,虛擬主機

CentOS7.3,Nginx,虛擬主機

配置基于IP的虛擬主機

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

ifconfig ens33:1 192.168.204.151ifconfig 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 / { }}

CentOS7.3,Nginx,虛擬主機

4. 重啟 nginx 服務

systemctl restart nginx

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

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

CentOS7.3,Nginx,虛擬主機

CentOS7.3,Nginx,虛擬主機

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


注:相關教程知識閱讀請移步到服務器教程頻道。
發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 南城县| 右玉县| 思茅市| 中宁县| 新晃| 高密市| 丁青县| SHOW| 寻甸| 肃南| 清原| 迭部县| 阳朔县| 麻城市| 陆川县| 滦南县| 晋州市| 阿瓦提县| 南江县| 东乡族自治县| 上思县| 云梦县| 库尔勒市| 松滋市| 织金县| 克什克腾旗| 丽水市| 拉孜县| 墨竹工卡县| 阜阳市| 溧水县| 衡水市| 长宁区| 阿合奇县| 防城港市| 彭阳县| 保定市| 东台市| 定陶县| 威信县| 沾益县|