2

So I'm trying to set up my site with Apache on Ubuntu 14.04.

I have created a mydomain.com.conf file in sites-available/. It looks like this;

mydomain.com.conf

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    ServerAdmin admin@mydomain.com

    DocumentRoot /var/www/mydomain.com/public_html

    ErrorLog ${APACHE_LOG_DIR}/mydomain.com/error.log
    CustomLog ${APACHE_LOG_DIR}/mydomain.com/access.log combined
</VirtualHost>

000-default.conf

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

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

For some reason apache doesn't seem to read mydomain.com.conf at all, it will always default to the configuration in 000-default.conf.

When visting my site I get a 403 Forbidden response.

  1. I've enabled the site by a2ensite mydomain.com and reloaded Apache.
  2. apachectl configtest returns Syntax OK

The error.log file for 000-default.conf says

[Wed Sep 03 11:01:48.717652 2014] [autoindex:error] [pid 5869] [client 2.71.93.10:55718] AH01276: Cannot serve directory /var/www/: No matching DirectoryIndex (index.php,index.html,index.cgi,index.pl,index.xhtml,index.htm) found, and server-generated directory index forbidden by Options directive

while the error log & access log for mydomain.com is empty.

My apache2.conf does a IncludeOptional sites-enabled/*.conf.

The security model in apache2.conf looks like this;

<Directory />
        Options FollowSymLinks
        AllowOverride None
        Require all denied
</Directory>

<Directory /var/www/>
        DirectoryIndex index.php, index.html
        AllowOverride None
        Require all granted
</Directory>

What's wrong?

1

Either your site is empty and not having any files or it is not having any file as mentioned int he Directory Index.

Another possibility is the permissions. The files or the directory of your site may not have permissions for apache's user to access.

  • There is an index.html. See my last code snippet where I define DirectoryIndex's for the /var/www/ directory. I'll take a look at permissions. – Unidan Sep 3 '14 at 16:19
  • @Unidan, I guess you're issue is solved. Please close the question by accepting my answer as correct. :D – beginer Sep 4 '14 at 8:00
  • No it's not solved yet. – Unidan Sep 4 '14 at 10:46
0

I too had a Apache2 log message including the phrase

Cannot serve directory /var/www/

which was strange because /var/www wasn't mentioned anywhere in my configuration.

But the message stopped when I did something about what I thought was a completely separate warning message:

Warning: DocumentRoot [/www/www.foo.bar/docs] does not exist

I surmise that when a DocumentRoot directory is not entirely ready for use, a default value, /var/www is (silently) used instead, which causes confusion.

0

My apache2.conf does a IncludeOptional sites-enabled/*.conf

In my case changing this to Include sites-enabled/*.conf solved the problem.


Some context to this solution:
This was on a docker build (FROM php:7.2-apache as of 2018-12-21) where the virtual hosts file had previously been loaded without any modifications thus giving us quite a headache when it suddenly didn't. If you need to reload apache after making this change without killing the container run /etc/init.d/apache2 reload (taken from this answer on SO).

-1

Deactivate 000-default with a2dissite and then restart apache.

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.