Reputation: 1
Apache2 configuration(below) of two virtual hosts on same IP in file /etc/apache2/sites-available/000-default.conf
# 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 apache2
will be listening , something like, listen(listenFD, 5)
.
listenFD
should look like,
retval = bind(listenFD, (struct sockaddr *) &servaddr, sizeof(servaddr));
where servaddr.sin_port = htons(80);
With given accept()
call syntax,
connfd = accept(listenFD, (struct sockaddr *) &cliaddr, &clilen);
Question:
Does httpd
server decide picking corresponding virtual host's DocumentRoot
after accept()
call? Is virtual host pick an application layer logic?
Upvotes: 0
Views: 27
Reputation: 41967
The virtual host cannot be resolved until the Host:
HTTP header field is parsed by the server, which is obviously after accept()
and after some amount of data has been read on the connected socket.
Upvotes: 3