CentOS 7.3配置Nginx虛擬主機(jī)的方法步驟
實(shí)驗(yàn)環(huán)境
一臺(tái)最小化安裝的CentOS 7.3虛擬機(jī)
配置基本環(huán)境
1. 安裝nginx
yum install -y epel-* yum isntall -y nginx vim
2. 建立虛機(jī)主機(jī)的站點(diǎn)根目錄
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

配置基于端口的虛擬主機(jī)
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. 啟動(dòng) nginx 服務(wù)
systemctl start nginx
4. 在宿主機(jī)訪問兩個(gè)站點(diǎn)
http://192.168.204.135:8081/
http://192.168.204.135:8082/

配置基于域名的虛擬主機(jī)
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ù)實(shí)際情況自己修改)
192.168.204.135 site1.test.com
192.168.204.135 site2.test.com

5. 在宿主機(jī)訪問兩個(gè)站點(diǎn)
http://site1.test.com/
http://site2.test.com/

配置基于IP的虛擬主機(jī)
1. 在虛擬機(jī)增加兩個(gè)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. 在宿主機(jī)訪問兩個(gè)站點(diǎn)
http://192.168.204.151/
http://192.168.204.152/

以上就是本文的全部內(nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。
- 阿里云Centos7安裝svn與配置講解
- CentOS7將Nginx添加系統(tǒng)服務(wù)的方法步驟
- Centos7.x下Nginx安裝及SSL配置與常用命令詳解
- centos6.5安裝python3.7.1之后無法使用pip的解決方案
- CentOS版本問題安裝Docker報(bào)錯(cuò)的解決方案
- Centos7修改主機(jī)名hostname的三種方法
- Linux centos下設(shè)置定時(shí)備份任務(wù)的方法步驟
- Linux centOS安裝JDK和Tomcat的教程
- 在CentOS7上搭建Jenkins+Maven+Git持續(xù)集成環(huán)境的方法
- Centos7.5配置java環(huán)境安裝tomcat的講解
相關(guān)文章
ubuntu 13.10編譯安裝mono環(huán)境(二)
接上篇,上篇僅安裝了Mono本身,并沒有安裝libgdiplus、gtk-sharp、mod_mono、MonoDevelop 等其他相關(guān)的軟件。 這篇主要是配置安裝libgdiplus。2014-07-07
淺析centos 7 自帶的 php 5.4升級(jí)為 5.6的方法
這篇文章主要介紹了centos 7 自帶的 php 5.4升級(jí)為 5.6的方法,需要的朋友可以參考下2018-12-12
Apache Flink 任意 Jar 包上傳導(dǎo)致遠(yuǎn)程代碼執(zhí)行漏洞復(fù)現(xiàn)問題(漏洞預(yù)警)
這篇文章主要介紹了Apache Flink 任意 Jar 包上傳導(dǎo)致遠(yuǎn)程代碼執(zhí)行漏洞復(fù)現(xiàn)問題,本文給出了修復(fù)建議和解決方案,需要的朋友可以參考下2019-11-11
Polysh命令實(shí)現(xiàn)多日志查詢的方法示例
大家應(yīng)該都知道Polysh是一個(gè)交互式命令,可以在一臺(tái)服務(wù)器上批量的對(duì)一批服務(wù)器進(jìn)行處理,運(yùn)行交互式命令。下面這篇文章主要給大家介紹了關(guān)于利用Polysh命令實(shí)現(xiàn)多日志查詢的相關(guān)資料,需要的朋友可以參考,下面來一起看看吧。2017-12-12
linux操作系統(tǒng)安裝sql developer步驟
本文介紹了linux安裝sql developer的步驟,大家參考使用吧2014-01-01

