Friday, January 28, 2011

Apache2: VirtualHost doesn't work...

hi, I'm having issues with redirecting a domain name to a specific folder on my server. I'm reading the istructions from here:

These are my configuration lines:

#This is the default Apache2 configuration lines
<VirtualHost *:80>
        ServerAdmin webmaster@localhost

        DocumentRoot /var/www

#This is what I've added
<VirtualHost *:80>
    DocumentRoot /var/www/astudio/sites/mywebsite
    ServerName www.mywebsite.com
</VirtualHost>

However it doesn't work.. the domain just not forward the user to my website.. is there something else I have to configure ?

  • Try this (presuming that www.mywebsite.com resolves to the ip address of your web server):

    #This is the default Apache2 configuration lines
    <VirtualHost *:80>
       ServerAdmin webmaster@localhost
       DocumentRoot /var/www/astudio/sites/mywebsite
       ServerName www.mywebsite.com
    </VirtualHost>
    
    From unixguy
  • Very little information to work with. Anyway...

    Can you connect to the server and get the default welcome page? Do you connect using the server name or the IP address? If you use the IP address, the you will get the default page. Did you reload the configuration?

    If you cannot connect, do you have the correct IP address? Is it a firewall/iptables issue? If apache listening on eth0 or only on the loopback interface?

    ====== EDIT

    If you connect using the IP address, you get the default page, no the one you want, because the Host: header in the HTTP request does not match with the ServerName defined in your VirtualHost. You have to access your website specifically with www.mywebsite.com to access your pages (You can add aliases, though).

    If you cannot connect with the name, then you have a DNS issue. A quick solution is to add the hostname and IP address to your hosts file. In Linux is /etc/hosts, in Windows it is somewhere in \windows\system32\... (I forget where exactly)

    ====== EDIT2

    If you access a web site with its IP address, the Host: header will contain the IP address, e.g. Host: 1.2.3.4:80. I have not tried it but you can try add the IP address to your VirtualHost as a ServerAlias. I assume you have a dedicated IP address.

    Patrick : @Dan Andreatta I connect to the server using the IP address. No firewall, I dunno if apache is listening on eth0 or only on the loopback interface but it works correctly.
    Dan Andreatta : Added some more info in the response
    Patrick : Is there something I can do from Apache, or is something to solve in control panel of my hosting service or by contacting their support ?
    Dan Andreatta : Added more info
  • Assuming you want to do name-based virtual hosting, do you have a NameVirtualHost *:80 directive?

    Also, do you have any other VirtualHost sections elsewhere in your configuration that might be interfering with this one?

0 comments:

Post a Comment