結合http詳解基於網域名稱的虛擬機器主機訪問詳細原理及過程

來源:互聯網
上載者:User

標籤:linux

伺服器如何響應

[[email protected] blog]# netstat -lntup|grep 80tcp        0      0 0.0.0.0:80                  0.0.0.0:*                   LISTEN      5784/nginx

啟動nginx服務,系統就監聽了原生80連接埠(80連接埠是原生所有網卡),所以只要用戶端請求任意一塊網卡的IP 80連接埠,nginx都會響應,用戶端請求任意一塊網卡ip的80連接埠,nginx服務都會看請求報文中其中有一個叫host:www.etiantian.org ,nginx伺服器接收到請求報文後請求的網域名稱,連接埠 ,會從nginx.conf設定檔中找虛擬機器主機,如果用戶端的請求報文中沒有虛擬機器主機名只有1個ip地址名字,那麼nginx伺服器只能把nginx.conf設定檔中預設第一個虛擬機器主機名以響應報文的形式發給用戶端。本文中下文中第一個預設虛擬機器主機名為www.etiantian.org    

也即是如果用戶端直接輸入nginx的ip地址,那麼nginx伺服器響應報文的時候預設響應第一個虛擬機器主機名字給用戶端。

[[email protected] conf]# cat nginx.confworker_processes  1;events {    worker_connections  1024;}http {    include       mime.types;    default_type  application/octet-stream;    sendfile        on;    keepalive_timeout  65;    server {        listen       80;        server_name  www.etiantian.org;        location / {            root   html/www;            index  index.html index.htm;        }    }    server {        listen       80;        server_name  bbs.etiantian.org;        location / {            root   html/bbs;            index  index.html index.htm;        }    }    server {        listen       80;        server_name  blog.etiantian.org;        location / {            root   html/blog;            index  index.html index.htm;        }    }}


本文出自 “sandshell” 部落格,請務必保留此出處http://sandshell.blog.51cto.com/9055959/1957731

結合http詳解基於網域名稱的虛擬機器主機訪問詳細原理及過程

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.