Apache2文件中同一IP上两个虚拟主机的配置(如下)

# Ensure that Apache listens on port 80
Listen 80
<VirtualHost *:80>
    DocumentRoot "/www/example1"
    ServerName www.example.com

    # Other directives here
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/www/example2"
    ServerName www.example.org

    # Other directives here
</VirtualHost>

Binary/etc/apache2/sites-available/000-default.conf将监听,类似于,apache2
listen(listenFD, 5)应该看起来像,
listenFD
其中retval = bind(listenFD, (struct sockaddr *) &servaddr, sizeof(servaddr));
使用给定的调用语法,
servaddr.sin_port = htons(80);
问题:
accept()服务器是否决定在调用后选择相应虚拟主机的connfd = accept(listenFD, (struct sockaddr *) &cliaddr, &clilen);?虚拟主机是否选择应用程序层逻辑?

最佳答案

除非服务器解析Host:HTTP头字段,否则无法解析虚拟主机,这显然是在accept()之后,并且在连接的套接字上读取了一些数据之后。

关于c - 在accept()调用之后,是否会选择虚拟主机的根目录?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/44751289/

10-12 03:00