首页 > Web开发 > 详细

结合http详解基于域名的虚拟主机访问详细原理及过程

时间:2017-08-20 09:58:20      阅读:283      评论:0      收藏:0      [点我收藏+]

服务器如何响应

[root@web01 blog]# netstat -lntup|grep 80
tcp        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服务器响应报文的时候默认响应第一个虚拟主机名字给客户端。

[root@web01 conf]# cat nginx.conf
worker_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详解基于域名的虚拟主机访问详细原理及过程

原文:http://sandshell.blog.51cto.com/9055959/1957731

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!