0

I have setup apache2 to use three domains. They are pointed correctly and I have setup the sites-available config files as the following:

Here is hfd-server.domain1.com, this one displays the default APACHE2 success page. However, it works with www.hfd-server.domain1.com. Don't understand.

<VirtualHost *:80>
        ServerAdmin email@domain1.com
        ServerName www.hfd-server.domain1.com
        DocumentRoot /var/www/hfd-server.domain1.com/public_html
        ServerAlias hfd-server.domain1.com

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

        #Other Directives Here
        <Directory /var/www/hfd-server.domain1.com/public_html>
                Options -Indexes +FollowSymLinks +MultiViews
                AllowOverride All
                Require all granted
        </Directory>
</VirtualHost>

Here are the other two working config files:

house.domain1.com

<VirtualHost *:80>
        ServerAdmin email@domain1.com
        ServerName www.house.domain1.com
        DocumentRoot /var/www/house-server.domain1.com/public_html
        ServerAlias house.domain1.com

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

        #Other Directives Here
        <Directory /var/www/house.domain1.com/public_html>
                Options -Indexes +FollowSymLinks +MultiViews
                AllowOverride All
                Require all granted
        </Directory>
</VirtualHost>

house.domain2.com

<VirtualHost *:80>
        ServerAdmin email@domain1.com
        ServerName www.house.domain2.com
        DocumentRoot /var/www/house.domain2.com/public_html
        ServerAlias house.domain2.com

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

        #Other Directives Here
        <Directory /var/www/house.domain2.com/public_html>
                Options -Indexes +FollowSymLinks +MultiViews
                AllowOverride All
                Require all granted
        </Directory>
</VirtualHost>

The access log and error log shows nothing out of the ordinary. Not sure why one would work but not the other one.

I didn't modify 000-default.conf. I was afraid to, so I made copies and just enabled them.

Is there anything else I can try, HFD-SERVER.domain1.com is linked to a control panel that I would like to have access.

UPDATE 12-28-17

I used sudo apachectl -t -D DUMP_VHOSTS and this is what it listed.

VirtualHost configuration: *:80  is a NameVirtualHost
default server HFD-SERVER.domain1.us (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost hfd-server.domain1.us (/etc/apache2/sites-enabled/000-default.conf:1)
port 80 namevhost www.hfd-server.domain1.us (/etc/apache2/sites-enabled/hfd-server.domain1.us.conf:1) alias hfd-server.domain1.us
port 80 namevhost house.domain1.us (/etc/apache2/sites-enabled/house.domain1.us.conf:1) alias www.house.domain1.us
port 80 namevhost house.domain2.us (/etc/apache2/sites-enabled/house.domain2.us.conf:1) alias www.house.domain2.us

Appears that the default server is 000-default.conf. Is there a way to make the hfd-domain1.us.conf the default server?

3
  • I dont think it would make a difference but if this was me .. I would most likely use ServerName hfd-server.domain1.com and ServerAlias www.hfd-server.domain1.com making the server name without the www and the alias with the www.. for all the entries ... in the sites-enabled folder what entries are in there is it the 000-default.conf along with the 3 new conf files you created? sounds like there is something different about the hfd-server config file .. not really sure what to suggest .. they all end in .conf. I found apache2 didnt like when I had config files that werent labeled .conf
    – John Orion
    Dec 28, 2017 at 5:09
  • I would also use apachectl -t -D DUMP_VHOSTS to see if all your virtual hosts are listed
    – John Orion
    Dec 28, 2017 at 5:09
  • I ran the command. I updated the question with the information. Appears that the default server is the 000-default.conf file. It's overwriting the hfd-server.domain1.us file. Dec 28, 2017 at 5:43

1 Answer 1

1

You can solve this in a few different ways

Change the 000-default.conf replace the relevant lines to match the hfd-domain1.us.conf and deleting the hfd-domain1.us.conf in /etc/apache2/sites-enabled then it would be the "000-default.conf" that points to the proper hdf-domain1.us with the proper folder structure and the other two would be show up as they did in the dump.

another way would be to change the 000-default.conf and change the ServerName and ServerAlias entries to something different so they dont have the same name as in hfd-domain1.us.conf and then you would have a default site pointing to these new settings .. and the 3 virtual ones you created.

and the last way is to go to the /etc/apache2/sites-enabled/ directory and remove or rename the shortcut to 000-default.conf changing the extension to 000-default.conf~

Updated: this was pointed out that it doesn't seem to allow you just to remove the file so I updated this answer with the information by the original poster the best way for this would be to run sudo a2dissite 000-deafult.conf to remove the 000-default.conf thus leaving the 3 virtual hosts enabled and should function as you want.

2
  • 1
    I'm going to accept this as the right answer because you gave me a good place to look. I tried renaming the default conf file and it broke apache. Apache wouldn't start because the site was still enabled. I realized that you can use sudo a2dissite 000-deafult.conf to disable the default config and it will take the first config file in its place. It resolved all issues. Thank you. Dec 28, 2017 at 22:33
  • ok glad you got it all figured out .. sorry about forgetting about the a2dissite command .. I never had to use that in the old days .. guess this is something new in updated versions of Apache2
    – John Orion
    Dec 29, 2017 at 0:18

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.