中文字幕在线观看,亚洲а∨天堂久久精品9966,亚洲成a人片在线观看你懂的,亚洲av成人片无码网站,亚洲国产精品无码久久久五月天

nginx 配置虛擬主機及設(shè)置方法

2014-08-14    來源:

容器云強勢上線!快速搭建集群,上萬Linux鏡像隨意使用


本文章總結(jié)了關(guān)于nginx 配置虛擬主機及設(shè)置多個虛擬主機兩種方法有需要的朋友可參考一下。

nginx可以使用server塊來設(shè)置多個虛擬主機,在server段中用server_name和listen指令來綁定域名和端口。例如:

 代碼如下

server {
 listen          80;
 server_name    www.netingcn.com;

 location / {
  root  netingcn_com;
  index index.html;
 }
}

server {
 listen          80;
 server_name     www.netingcn.net;

 location / {
  root  netingcn_net;
  index index.html;
 }
}




上述配置就是指定了兩個虛擬主機,分別是www.netingcn.com和www.netingcn.net?赡茉谀承﹏ginx的版本中上述的配置并不能很好的工作,出現(xiàn)的情況是所有的請求都是由第一個server處理的。

造成這個的原因是沒有配置一個”catch all”的缺省server,所謂缺省即是把不匹配配置指定的虛擬主機的請求都交給缺省server來處理。缺省server的配置如下:

 代碼如下

server {
 listen 80 default_server;
 server_name _; # this is just an invalid value which will never trigger on a real hostname.
 access_log logs/default.access.log main;

 server_name_in_redirect off;

 root  /var/www/default/htdocs;
}

vps 上安裝了 nginx。用多個子域名,每個子域名到不同的目錄。

如:

 代碼如下

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 正常工作了。


標(biāo)簽: vps 綁定域名 代碼 配置虛擬主機 虛擬主機 域名 子域名

版權(quán)申明:本站文章部分自網(wǎng)絡(luò),如有侵權(quán),請聯(lián)系:west999com@outlook.com
特別注意:本站所有轉(zhuǎn)載文章言論不代表本站觀點!
本站所提供的圖片等素材,版權(quán)歸原作者所有,如需使用,請與原作者聯(lián)系。

上一篇:mysql mongodb 定時備份數(shù)據(jù)庫腳本

下一篇:DNS問題容易導(dǎo)致云服務(wù)器網(wǎng)站故障