0

I am having a really annoying issue where my newly created Apache Vhost is causing config error. I initially use cp command to copy existing and working vhost and just changed the DocumentRoot. Apache would fail to reload and restart.

Running apache2 -t results in error below:

apache2: Syntax error on line 220 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/sites-enabled/test.example.com.conf: /etc/apache2/sites-enabled/test.example.com.conf:1: <VirtualHost> was not closed.

Here is my vhost stripped to the bare bones (I am running this exact code):

<VirtualHost *:443>
        ServerAdmin example@email.com
        DocumentRoot /var/www/test

        ServerName      ddns.example.com
        ServerAlias     www.test.example.com
</VirtualHost>

If I disable this vhost Apache starts fine and no config errors are shows from apache2 -t command. I've gone and manually retyped the vhost opening/closing tags and checked for empty space. test directory does exist and has www-root:www-root ownership. What is causing this seemingly false error?

DominicM
  • 251
  • 3
  • 6
  • 12

1 Answers1

1

Included Apache configuration files like the virtual host configuration files are read in order. Despite the error points to this file and the line number 1 where it actualizes, the problem is a missing </VirtualHost> at the end of the previous file. That's the previous file in an alphabetical order. It's not an error until there's an unexpected <VirtualHost> statement.

Esa Jokinen
  • 46,944
  • 3
  • 83
  • 129
  • I have now checked all sites-enabled vhosts and they all have closing tags. This is the only vhost causing issues and its in the middle alphabetically. Also wouldn't apache -t show an error if tags not closed? I bet it's something particularly simple but I cannot see it... – DominicM Mar 24 '20 at 23:03
  • Also if I add at the top of the troublesome vhost file I get and error: "apache2: Syntax error on line 220 of /etc/apache2/apache2.conf: Syntax error on line 1 of /etc/apache2/sites-enabled/test.example.com.conf: without matching section" – DominicM Mar 24 '20 at 23:16