新聞中心
這里有您想知道的互聯(lián)網(wǎng)營銷解決方案
Nginx配置虛擬主機(jī)具體的代碼配置
Vps 上安裝了 Nginx。但是我們還需要Nginx配置虛擬主機(jī),那么要如何才能進(jìn)行Nginx配置虛擬主機(jī)呢?接下來我們就詳細(xì)看看有關(guān)虛擬主機(jī)在Nginx上的配置問題。用多個子域名,每個子域名到不同的目錄。

專注于為中小企業(yè)提供做網(wǎng)站、成都做網(wǎng)站服務(wù),電腦端+手機(jī)端+微信端的三站合一,更高效的管理,為中小企業(yè)武昌免費做網(wǎng)站提供優(yōu)質(zhì)的服務(wù)。我們立足成都,凝聚了一批互聯(lián)網(wǎng)行業(yè)人才,有力地推動了上1000+企業(yè)的穩(wěn)健成長,幫助中小企業(yè)通過網(wǎng)站建設(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 目錄。后來看了官方示例:http://wiki.Nginx.org/NginxVirtualHostExample,提到有個 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;
- }
- }
- }
加上這個 default 就可使 a.chenlb.com 和 b.chenlb.com 正常工作了。以上就是對Nginx配置虛擬主機(jī)的詳細(xì)介紹。
【編輯推薦】
- Nginx服務(wù)器的性能依然強(qiáng)勁
- Nginx配置中運行與啟動的詳細(xì)介紹
- Nginx緩存如何避免傳統(tǒng)緩存的錯誤
- Nginx php如何解決502 Bad Gateway錯誤
- Nginx proxy反向代理的十五大技術(shù)特點
分享標(biāo)題:Nginx配置虛擬主機(jī)具體的代碼配置
鏈接分享:http://www.dlmjj.cn/article/djhhhhd.html


咨詢
建站咨詢
