Problem with virtual hosts

March 25, 2015 4k views
WordPress DNS Apache Server Optimization Miscellaneous Ubuntu

Hi,

I set up virtual hosts on ubuntu 12.04. But not everything is going as it should. I have two files in sites-enabled. One file holds the code for one site, and it works, one for a dozen other sites, and they work also. Except now I try to add another one to the second file, and the site cannot be found. Strangely enough, the first site in that file is also the site that is visible when I go to the ip of my server 188.226.137.114, skyo.be. The code is always the same:

<VirtualHost *:80>
ServerAdmin webmaster@localhost
DocumentRoot /var/www/skyo/publichtml
ServerName www.skyo.be
Serveralias sky.be
Serveralias www.skyo.be
ErrorLog /var/www/skyo/logs/error.log
Loglevel warn
CustomLog /var/www/skyo/logs/access.log combined
<Directory /var/www/skyo/public
html>
AllowOverride All
Order allow,deny
allow from all
</Directory>

</VirtualHost>

This is the first site in that file, when I put another site above this code, this site is visible on skyo.be. So is the new site I wanted to add. So I can access the site, all the redirections work.

I know this is kind of a mess, I would like to have different files, so for each site one file in sites-available instead of one (strangely enough the second file works). I followed the tutorial on creating virtual hosts:https://www.digitalocean.com/community/tutorials/how-to-set-up-apache-virtual-hosts-on-ubuntu-12-04-lts

Does anyone have an idea how to get this fixed?

thanks!!

6 comments
  • First off, I've cleaned up your config:

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/skyo/publichtml
        ServerName www.skyo.be
        Serveralias sky.be
        ErrorLog /var/www/skyo/logs/be-error.log
        Loglevel warn
        CustomLog /var/www/skyo/logs/access.log combined
        <Directory /var/www/skyo/publichtml>
            AllowOverride All
            Order allow,deny
            allow from all
        </Directory>
    </VirtualHost>
    

    You don't set an alias that points to the ServerName. Also, only have one ServerAlias. They can be set like this:

    ServerName example.com
    ServerAlias www.example.com my.example.com
    

    Next, run this, and give me the output:

    apache2ctl -S
    
  • @JonsJava

    tnx!

    I made a mistake in the alias of skyo, that was why it pointed toward that site, I guess. Still no luck with the new site franklefebure.be. It shows on the ip of the server but not on the domainname. Maybe it is a problem with the A records.

    <VirtualHost *:80>
    ServerAdmin webmaster@localhost

    DocumentRoot /var/www/franklefebure/public_html
    ServerName www.franklefebure.be
    Serveralias franklefebure.be

    ErrorLog /var/www/franklefebure/logs/error.log
    Loglevel warn
    CustomLog /var/www/franklefebure/logs/access.log combined

    <Directory /var/www/franklefebure/public_html>
    AllowOverride All
    Order allow,deny
    allow from all
    </Directory>

    </VirtualHost>

    Output:

    [Wed Mar 25 08:50:04 2015] [warn] The Alias directive in /etc/apache2/conf.d/phpmyadmin.conf at line 3 will probably never match because it overlaps an earlier Alias.
    Loaded Modules:
    coremodule (static)
    logconfigmodule (static)
    logiomodule (static)
    mpmpreforkmodule (static)
    httpmodule (static)
    somodule (static)
    aliasmodule (shared)
    authbasicmodule (shared)
    authnfilemodule (shared)
    authzdefaultmodule (shared)
    authzgroupfilemodule (shared)
    authzhostmodule (shared)
    authzusermodule (shared)
    autoindexmodule (shared)
    cgimodule (shared)
    deflatemodule (shared)
    dirmodule (shared)
    envmodule (shared)
    mimemodule (shared)
    negotiationmodule (shared)
    php5module (shared)
    reqtimeoutmodule (shared)
    rewritemodule (shared)
    setenvifmodule (shared)
    status_module (shared)
    Syntax OK

  • I apologize. I meant for you to give me the output for "apache2ctl -S"

  • wildcard NameVirtualHosts and default servers:
    *:80 is a NameVirtualHost
    default server www.franklefebure.be (/etc/apache2/sites-enabled/franklefebure:1)
    port 80 namevhost www.franklefebure.be (/etc/apache2/sites-enabled/franklefebure:1)
    port 80 namevhost www.skyo.be (/etc/apache2/sites-enabled/skyo:1)
    port 80 namevhost www.tcpajottenland.be (/etc/apache2/sites-enabled/skyo:17)
    port 80 namevhost www.generationalbator.be (/etc/apache2/sites-enabled/skyo:37)
    port 80 namevhost www.gorgonmotors.be (/etc/apache2/sites-enabled/skyo:56)
    port 80 namevhost www.lapsuslanguages.be (/etc/apache2/sites-enabled/skyo:75)
    port 80 namevhost www.dance-inn.be (/etc/apache2/sites-enabled/skyo:94)
    port 80 namevhost www.demo.schoolbox.be (/etc/apache2/sites-enabled/skyo:113)
    port 80 namevhost www.demo2.schoolbox.be (/etc/apache2/sites-enabled/skyo:132)
    port 80 namevhost www.fr.melkopschool.be (/etc/apache2/sites-enabled/skyo:151)
    port 80 namevhost www.voka.theantennapub.be (/etc/apache2/sites-enabled/skyo:170)
    port 80 namevhost www.sketchingtheworld.org (/etc/apache2/sites-enabled/skyo:189)
    port 80 namevhost www.pantalone.be (/etc/apache2/sites-enabled/skyo:209)
    port 80 namevhost www.vendiscapital.com (/etc/apache2/sites-enabled/vendiscapital:1)

    as you see I created a different file for franklefebure, which I intend to do for all the sites now.

  • Well crap. There be the issue:

     whois franklefebure.be
    ................
    Nameservers:
            ns1.dreamhost.be
            ns2.dreamhost.be
            ns3.dreamhost.be
    
    
    user@server:~$ ping ns1.dreamhost.be
    ping: unknown host ns1.dreamhost.be
    
    user@server:~$  nslookup ns1.dreamhost.be
    Server:         8.8.8.8
    Address:        8.8.8.8#53
    
    ** server can't find ns1.dreamhost.be: NXDOMAIN
    

    TL;DR: dreamhost.be nameservers are inaccurate. They can't be resolved, so that domain can't be resolved.

    The fix:

    nslookup franklefebure.be ns1.dreamhost.com
    Server:         ns1.dreamhost.com
    Address:        66.33.206.206#53
    
    Name:   franklefebure.be
    Address: 188.226.137.114
    

    change the nameservers from

    ns1.dreamhost.be
    ns2.dreamhost.be
    ns3.dreamhost.be
    

    to

    ns1.dreamhost.com
    ns2.dreamhost.com
    ns3.dreamhost.com
    
  • wow! I'm officially an idiot. Sorry for wasting your time.

    Anyway, it helped me clean up the code!

    thank you

2 Answers

The vhosts are meant to be in /etc/apache2/sites-available not sites-enabled. Once you've created your vhost in sites-available you need to then run a2ensite and choose the config you want to enable which will create a link in sites-enabled.

Have another answer? Share your knowledge.