這篇文章主要介紹“nginx基于端口如何配置虛擬主機”的相關(guān)知識,小編通過實際案例向大家展示操作過程,操作方法簡單快捷,實用性強,希望這篇“nginx基于端口如何配置虛擬主機”文章能幫助大家解決問題。

成都創(chuàng)新互聯(lián)一直在為企業(yè)提供服務(wù),多年的磨煉,使我們在創(chuàng)意設(shè)計,成都全網(wǎng)營銷到技術(shù)研發(fā)擁有了開發(fā)經(jīng)驗。我們擅長傾聽企業(yè)需求,挖掘用戶對產(chǎn)品需求服務(wù)價值,為企業(yè)制作有用的創(chuàng)意設(shè)計體驗。核心團隊擁有超過十年以上行業(yè)經(jīng)驗,涵蓋創(chuàng)意,策化,開發(fā)等專業(yè)領(lǐng)域,公司涉及領(lǐng)域有基礎(chǔ)互聯(lián)網(wǎng)服務(wù)成都多線機房、手機APP定制開發(fā)、手機移動建站、網(wǎng)頁設(shè)計、網(wǎng)絡(luò)整合營銷。
一、創(chuàng)建網(wǎng)站目錄及文件:
[root@localhost data]# tree /data /data └── wwwroot ├── www.1.com_8080 │ └── index.html └── www.1.com_8081 └── index.html
二、修改nginx.conf:
[root@localhost nginx]# vim /usr/local/nginx/conf/nginx.conf
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
default_type application/octet-stream;
keepalive_timeout 65;
include vhost/*.conf; #vhost目錄下會包含所有的虛擬主機的配置文件
}三、創(chuàng)建虛擬主機的配置文件目錄:
[root@localhost conf]mkdir /usr/local/nginx/conf/vhost
四、創(chuàng)建虛擬主機配置文件:
[root@localhost nginx]# vim /usr/local/nginx/conf/vhost/www.1.com.8080.conf
server{
listen 8080;
server_name 1.com www.1.com;
index index.html;
root /data/wwwroot/www.1.com_8080;
}[root@localhost nginx]# vim /usr/local/nginx/conf/vhost/www.1.com.8081.conf
server{
listen 8081;
server_name 1.com www.1.com;
index index.html;
root /data/wwwroot/www.1.com_8081;
}[root@localhost nginx]# vim /usr/local/nginx/conf/vhost/default.conf
server{
listen 80 default_server; #使用default_server指定nginx的默認虛擬主機
deny all;
}若使用其他域名來訪問虛擬主機時,會匹配到默認虛擬主機,該配置會拒絕未定義的域名的虛擬主機。若不配置該選項,默認排在最前邊的server會成為默認虛擬主機。
五、測試配置文件是否存在問題:
[root@localhost root]# cd /usr/local/nginx/sbin [root@localhost sbin]# ./nginx -t nginx: the configuration file /usr/local/nginx/conf/nginx.conf syntax is ok nginx: configuration file
六、當(dāng)配置文件修改時,可以使用一下命令重新加載配置文件
[root@localhost sbin]# ./nginx -s reload
關(guān)于“nginx基于端口如何配置虛擬主機”的內(nèi)容就介紹到這里了,感謝大家的閱讀。如果想了解更多行業(yè)相關(guān)的知識,可以關(guān)注創(chuàng)新互聯(lián)行業(yè)資訊頻道,小編每天都會為大家更新不同的知識點。
網(wǎng)頁題目:nginx基于端口如何配置虛擬主機
地址分享:http://www.chinadenli.net/article34/peegse.html
成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供App開發(fā)、面包屑導(dǎo)航、外貿(mào)網(wǎng)站建設(shè)、用戶體驗、動態(tài)網(wǎng)站、企業(yè)建站
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)