新聞中心
Vps 上安裝了 Nginx。但是我們還需要Nginx配置虛擬主機(jī),那么要如何才能進(jìn)行Nginx配置虛擬主機(jī)呢?接下來(lái)我們就詳細(xì)看看有關(guān)虛擬主機(jī)在Nginx上的配置問(wèn)題。用多個(gè)子域名,每個(gè)子域名到不同的目錄。

專注于為中小企業(yè)提供做網(wǎng)站、成都做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)武昌免費(fèi)做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動(dòng)了上1000+企業(yè)的穩(wěn)健成長(zhǎng),幫助中小企業(yè)通過(guò)網(wǎng)站建設(shè)實(shí)現(xiàn)規(guī)模擴(kuò)充和轉(zhuǎn)變。
如:
- http {
- server {
- listen 80;
- server_name a.chenlb.com;
- access_log logs/a.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /home/www/host_a/;
- }
- }
- server {
- listen 80;
- server_name b.chenlb.com;
- access_log logs/b.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /home/www/host_b/;
- }
- }
- }
- http {
- server {
- listen 80;
- server_name a.chenlb.com;
- access_log logs/a.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /home/www/host_a/;
- }
- }
- server {
- listen 80;
- server_name b.chenlb.com;
- access_log logs/b.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /home/www/host_b/;
- }
- }
- }
結(jié)果發(fā)現(xiàn)用 b.chenlb.com 還是指到 host_a 目錄。后來(lái)看了官方示例:http://wiki.Nginx.org/NginxVirtualHostExample,提到有個(gè) default 的匹配,如:
- http {
- server {
- listen 80 default;
- server_name _;
- access_log logs/default.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /var/www/default/htdocs;
- }
- }
- }
- http {
- server {
- listen 80 default;
- server_name _;
- access_log logs/default.access.log main;
- server_name_in_redirect off;
- location / {
- index index.html;
- root /var/www/default/htdocs;
- }
- }
- }
加上這個(gè) default 就可使 a.chenlb.com 和 b.chenlb.com 正常工作了。以上就是對(duì)Nginx配置虛擬主機(jī)的詳細(xì)介紹。
【編輯推薦】
- Nginx服務(wù)器的性能依然強(qiáng)勁
- Nginx配置中運(yùn)行與啟動(dòng)的詳細(xì)介紹
- Nginx緩存如何避免傳統(tǒng)緩存的錯(cuò)誤
- Nginx php如何解決502 Bad Gateway錯(cuò)誤
- Nginx proxy反向代理的十五大技術(shù)特點(diǎn)
當(dāng)前文章:Nginx配置虛擬主機(jī)具體的代碼配置
標(biāo)題路徑:http://fisionsoft.com.cn/article/djhhhhd.html


咨詢
建站咨詢
