您的位置:首页 > 理论基础 > 计算机网络

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

2017-08-20 00:11 246 查看
服务器如何响应
[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;
}
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  linux
相关文章推荐