這篇文章主要講解了“CentOS怎么配置Nginx虛擬主機(jī)”,文中的講解內(nèi)容簡(jiǎn)單清晰,易于學(xué)習(xí)與理解,下面請(qǐng)大家跟著小編的思路慢慢深入,一起來研究和學(xué)習(xí)“CentOS怎么配置Nginx虛擬主機(jī)”吧!
創(chuàng)新互聯(lián)專注為客戶提供全方位的互聯(lián)網(wǎng)綜合服務(wù),包含不限于網(wǎng)站建設(shè)、做網(wǎng)站、河南網(wǎng)絡(luò)推廣、小程序開發(fā)、河南網(wǎng)絡(luò)營(yíng)銷、河南企業(yè)策劃、河南品牌公關(guān)、搜索引擎seo、人物專訪、企業(yè)宣傳片、企業(yè)代運(yùn)營(yíng)等,從售前售中售后,我們都將竭誠(chéng)為您服務(wù),您的肯定,是我們最大的嘉獎(jiǎng);創(chuàng)新互聯(lián)為所有大學(xué)生創(chuàng)業(yè)者提供河南建站搭建服務(wù),24小時(shí)服務(wù)熱線:18980820575,官方網(wǎng)址:chinadenli.net
實(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/
感謝各位的閱讀,以上就是“CentOS怎么配置Nginx虛擬主機(jī)”的內(nèi)容了,經(jīng)過本文的學(xué)習(xí)后,相信大家對(duì)CentOS怎么配置Nginx虛擬主機(jī)這一問題有了更深刻的體會(huì),具體使用情況還需要大家實(shí)踐驗(yàn)證。這里是創(chuàng)新互聯(lián),小編將為大家推送更多相關(guān)知識(shí)點(diǎn)的文章,歡迎關(guān)注!
分享名稱:CentOS怎么配置Nginx虛擬主機(jī)
文章路徑:http://chinadenli.net/article0/ppggoo.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供外貿(mào)網(wǎng)站建設(shè)、建站公司、網(wǎng)站收錄、定制開發(fā)、網(wǎng)站排名、微信小程序
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請(qǐng)盡快告知,我們將會(huì)在第一時(shí)間刪除。文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如需處理請(qǐng)聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時(shí)需注明來源: 創(chuàng)新互聯(lián)