• Some users have recently had their accounts hijacked. It seems that the now defunct EVGA forums might have compromised your password there and seems many are using the same PW here. We would suggest you UPDATE YOUR PASSWORD and TURN ON 2FA for your account here to further secure it. None of the compromised accounts had 2FA turned on.
    Once you have enabled 2FA, your account will be updated soon to show a badge, letting other members know that you use 2FA to protect your account. This should be beneficial for everyone that uses FSFT.

Apache 2 vhost question.

PHPForever

n00b
Joined
Jan 11, 2005
Messages
22
Well, just when I tought I knew everything about Virtual Hosts.... to the question.

I have two websites hosted on my Apache server as vhosts. They both work fine.

Here are the entries in the httpd.conf file (substituting site1 and site2 for the real domains - I'm ashamed of my websites)


NameVirtualHost *:80

<VirtualHost *:80>
ServerName site1.com
DocumentRoot C:/wwwroot/site1/wwwpublic
ErrorLog C:/wwwroot/site1/logs/errorlog
</VirtualHost>

<VirtualHost *:80>
ServerName site2.com
DocumentRoot C:/wwwroot/site2.com/wwwpublic
ErrorLog C:/wwwroot/ site2.com/logs/errorlog
</VirtualHost>

Now I have registered another domain, in this case site3.com which is pointing to the server's IP address. site3.com does not have a vhost entry yet. What was unexpected is that when I visit site3.com apache answers with site1.com. If I switch the order of the vhost entries, then apache answers with site2.com. Is that behaviour normal? Please explain.
 
whichever vhost is listed first is the default host. often this would be the main domain and other vhosts would be subdomains. thus any invalid subdomain would simply go to the main site. in this case any domains that point to your server's IP but aren't set up with their own vhost go to the default vhost.

so to answer your question, this is normal

from http://httpd.apache.org/docs-2.0/vhosts/name-based.html
Now when a request arrives, the server will first check if it is using an IP address that matches the NameVirtualHost. If it is, then it will look at each <VirtualHost> section with a matching IP address and try to find one where the ServerName or ServerAlias matches the requested hostname. If it finds one, then it uses the configuration for that server. If no matching virtual host is found, then the first listed virtual host that matches the IP address will be used.

As a consequence, the first listed virtual host is the default virtual host. The DocumentRoot from the main server will never be used when an IP address matches the NameVirtualHost directive. If you would like to have a special configuration for requests that do not match any particular virtual host, simply put that configuration in a <VirtualHost> container and list it first in the configuration file.
 
tim_m said:
whichever vhost is listed first is the default host. often this would be the main domain and other vhosts would be subdomains. thus any invalid subdomain would simply go to the main site. in this case any domains that point to your server's IP but aren't set up with their own vhost go to the default vhost.

so to answer your question, this is normal

from http://httpd.apache.org/docs-2.0/vhosts/name-based.html

Right now I feel quite stupid... turning red. Thz for the info... I don't believe I overlooked that detail in the manual pages. :rolleyes:
 
Back
Top