apache2 - VHOST not working in Apache

  • Starx

    I got a LAMP server working in Ubuntu 11.04. Now the problem is that the websites have to enabled and disabled from the terminal. All all of them have to be accessed from http://localhost which is not so much efficient. So I created a VHOSTS, using some tutorials off the net. Here is the coding for it

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        Servername site.com
        ServerAlias www.site.com
        DocumentRoot /home/starx/public_html/site/public
        <Directory />
            Options FollowSymLinks
            AllowOverride None
        <Directory /home/starx/public_html/site/public>
            Options Indexes FollowSymLinks MultiViews
            AllowOverride None
            Order allow,deny
            allow from all
        ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
        <Directory "/usr/lib/cgi-bin">
            AllowOverride None
            Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
            Order allow,deny
            Allow from all
        ErrorLog ${APACHE_LOG_DIR}/site-error.log
        # Possible values include: debug, info, notice, warn, error, crit,
        # alert, emerg.
        LogLevel warn
        CustomLog ${APACHE_LOG_DIR}/site-access.log combined
        Alias /doc/ "/usr/share/doc/"
        <Directory "/usr/share/doc/">
            Options Indexes MultiViews FollowSymLinks
            AllowOverride None
            Order deny,allow
            Deny from all
            Allow from ::1/128

    Now, still I can't access the page in http://site.com but if i access using http://localhsot/ it is accessed.

    I have disabled all others site including default and have just enabled one site i.e. site

    How to fix this?

  • Answers
  • Eliah Kagan

    I was just trying to get this to work, and after looking around a bit I found out what was going wrong for me.

    I am running xampp (lampp) 1.80 for Ubuntu 12.04.

    open /opt/lampp/etc/httpd.conf

    See Line 488

    # Virtual hosts  
    # Include etc/extra/httpd-vhosts.conf

    remove the "#" from the include.
    A new install does not load the httpd-vhosts.conf out of the box.

  • Jorge Castro

    According to /usr/share/doc/apache2/README.Debian.gz, if you wish to create definitions for additional sites, you will want to place individual site configuration snippets in /etc/apache2/sites-available/ (see /etc/apache2/sites-available/default for an example). You can then enable and disable sites on a given host with the a2ensite(8) and a2dissite(8) commands. Note that this may not work precisely as described if the distributed configurations have been changed significantly.

    If a site is enabled in this way, and continues not to appear to work, you will want to make sure that the web server can resolve the name of the new site in a way that matches an IP address the web server believes it is assigned: the simplest way is probably to check with w3m https://my.new.secure.site from the server. You also want to verify that the client resolves the name in a way that causes it to reach the server in question (although the resolved IP does not need to match one the server uses). For insecure sites, this is easiest with telnet my.new.site 80 and, once the connection is complete (there is no prompt), entering the following three lines (note that the third is blank, but you must press enter a third time):

    GET / HTTP/1.1
    Host: my.new.site

    If these work, anything else is a browser problem. If the first succeeds and the second fails, there is probably something odd in the network layer (NAT, proxies, etc.): exactly how to troubleshoot this depends far too much on the network topology and devices present: please ask another question with specifics if this applies to you.

    If the first test fails, double-check the name service available on the server and the IP addresses assigned to the server (ifconfig -a). Also check your site access logs to verify that you see a connection at about the right time. Lastly, make sure that your virtual host is listening by name, rather than by IP, and does not filter the results for / based on IP in your VirtualHost directive.

  • SH.

    I'm not sure this is what you want.

    Replace your codes with this simple short codes.

    <VirtualHost *:80>
       ServerAdmin admin@localhost
       DocumentRoot YourDocumentRoot
       ServerName site.com
       ServerAlias www.site.com
       ErrorLog localhost
       CustomLog localhost-access_log common

    You can read more about vhost here

  • Capt.Nemo

    Have you added site.com and www.site.com to your /etc/hosts file to make sure that the dns routing is correct? You can try nslookup site.com to test the dns.

    If you want to make sure that http://localhost does not work, delete the /etc/apache2/default, default-ssl files and use a single virtualhost.

  • Related Question

    configuration - Cannot get 'default' Apache VirtualHost to work
  • Ross

    I've changed this from the original VHost but it should still work in my mind:

    Listen 80
    NameVirtualHost *:80
    <VirtualHost *:80>
     ServerName localhost
     ServerAdmin ross@localhost
     DocumentRoot /var/www
     <Directory /var/www/>
      Options Indexes FollowSymLinks MultiViews
      AllowOverride None
      Order allow,deny
      allow from all
     ErrorLog /var/log/apache2/error.log
     # Possible values include: debug, info, notice, warn, error, crit,
     # alert, emerg.
     LogLevel warn
     CustomLog /var/log/apache2/access.log combined

    The only difference between this and other working VHosts is that /var/www requires higher privileges to access it - I get a "Could not connect" error which I assume is a 500 error (Chrome hides the status codes and I can't remember). What can I do to make this work?

  • Related Answers
  • jathanism

    Try performing a manual connection using telnet from a terminal window:

    telnet localhost 80

    If you receive a connection refused message, the daemon is not running or starting up propertly. From there it would be a good idea to inspect your Apache error log (/var/log/apache2/error.log) to find out why.

  • Dennis Kaarsemaker

    Could not connect is not a 500 error. It means apache is either not running or not reachable.

  • Scaine

    This is a guess, but I think Apache runs as the www-user login, or similar. Does it have rights to the root of /var/www? I think by default, Apache points to symlinks off an /etc/apache2/default directory or something like that. Working from memory here, and no expert though. Sorry.