Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

650
Views
Apache2: Expected </Directory> but saw </VirtualHost>

I recently started an apache2 server on my raspi, working totally fine. Today, I had to restart my server, without ever changing my config files, and for some reason got the following error:

apache2: Syntax error on line 225 of /etc/apache2/apache2.conf: 
Syntax error on line 30 of /etc/apache2/sites-enabled/default-ssl.conf: 
Expected </Directory> but saw </VirtualHost>

Well, I thought, lets track that down:

/etc/apache2/apache2.conf

   [...]

   217  
   218  # Include of directories ignores editors' and dpkg's backup files,
   219  # see README.Debian for details.
   220  
   221  # Include generic snippets of statements
   222  IncludeOptional conf-enabled/*.conf
   223  
   224  # Include the virtual host configurations:
   225  IncludeOptional sites-enabled/*.conf
   226  
   227  # vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Nothing wrong with line 255. Actually included by apache itself.

/etc/apache2/sites-enabled/default-ssl.conf

     1  <IfModule mod_ssl.c>
     2      <VirtualHost *:443>
     3  
     4          ServerAdmin myemail@gmail.com
     5          ServerName mydomain.net
     6  
     7          DocumentRoot /var/www/html
     8  
     9          <Directory /var/www/html>
    10              Options Indexes FollowSymLinks
    11              AllowOverride None
    12              Require all granted
    13          </Directory>
    14  
    15          ErrorLog ${APACHE_LOG_DIR}/error.log combined
    16          CustomLog ${APACHE_LOG_DIR}/access.log combined
    17  
    18          SSLEngine on
    19          SSLCertificateFile  /etc/apache2/ssl/mydomain.net.cer
    20          SSLCertificateKeyFile /etc/apache2/ssl/mydomain.net.key
    21          SSLCertificateChainFile /etc/apache2/ssl/mydomain.net.intermediate.cer
    22  
    23          <Directory /var/www/html/Humboldtplan>
    24              AuthType Basic
    25              AuthName "Restricted Content"
    26              AuthUserFile /etc/apache2/.passwords/humboldt
    27              Require valid-user
    28          </Directory>
    29  
    30      </VirtualHost>
    31  </IfModule>

Now I can really not figure out the problem here. I broke my head down on what could be wrong but everything seems right to me. All tags are properly closed, the </VirtualHost> is where it should be. Also, the exact same config worked before, whats the problem so suddenly?

I thought it might be an unrelated problem like memory, so I did all the basic stuff. Updated all the packages, rebooted my raspi, still didn't work, shut it down and unplugged it in order to fix eventual memory issues, still didn't work.

What is wrong here?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Well the answer is a disappointing "whitespace" error. Printing out the escaped characters with cat -An [...] gave me the following:

     7  ^I^IDocumentRoot /var/www/html$
     8  $
     9  ^I^I<Directory /var/www/html>$
    10  M-bM-^@M-^K^I^I^IOptions Indexes FollowSymLinks$
    11  M-bM-^@M-^K^I^I^IAllowOverride None$
    12  ^I^I^IRequire all granted$
    13  M-bM-^@M-^K^I^I</Directory>$
    14  $
    15  ^I^I#ErrorLog ${APACHE_LOG_DIR}/error.log$
    16  ^I^I#CustomLog ${APACHE_LOG_DIR}/access.log combined$
    17  $

I have no idea what exactly M-bM-^@M-^K means (other than some form of UTF-8 whitespace characters) nor how they actually ended up in that file (especially as I have, as I said, not edited them while the server was up). But removing those seems to have resolved my problem.

These were especially surprising as they were neither stopping my cursor from hopping from tab to tab, nor formatting the document in any way. I only noticed when trying to comment out the specific lines, as they werent marked blue (as "commented") after i put a hashtag in front of them.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!