0

Im pulling my hair out with Apache2 on Ubuntu 18.04.

I have a couple of domains that point to Vhosts, they seem to work but for some reasons when browsing to the IP directly, if just forwards to one of the vhosts and not the root of the /var/www/html directory.. What is going on? This works on Centos but not on Ubuntu.

    <VirtualHost *:80>
            ServerAdmin webmaster@localhost
            DocumentRoot /var/www/html

            <Directory /var/www/html/>
                Options Indexes FollowSymLinks
                AllowOverride All
                Require all granted
            </Directory>

            ErrorLog ${APACHE_LOG_DIR}/error.log
            CustomLog ${APACHE_LOG_DIR}/access.log combined

            <IfModule mod_dir.c>
                DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
            </IfModule>
</VirtualHost>

    <VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName domain.com
        ServerAlias domain.com
        DocumentRoot /var/www/html/domain.com/
        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined
    </VirtualHost>

1 Answers1

0

Do you have a 000-default.conf in sites enabled ? If not maybe create it and move the first virtual into it:

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        DocumentRoot /var/www/html

        <Directory /var/www/html/>
            Options Indexes FollowSymLinks
            AllowOverride All
            Require all granted
        </Directory>

        ErrorLog ${APACHE_LOG_DIR}/error.log
        CustomLog ${APACHE_LOG_DIR}/access.log combined

        <IfModule mod_dir.c>
            DirectoryIndex index.php index.pl index.cgi index.html index.xhtml index.htm
        </IfModule>

Now create a .conf for each of your other virtuals with ascending files like 10-this-domain and 20-that-domain

In your apache2.conf you should maybe have this line

IncludeOptional sites-enabled/*.conf

the directory sites-enabled holds all the hosts files for the virtuals

Works out of the box on my Ubuntu, I just drop new hosts into sites-enabled

Alec
  • 16