Apache Error (AH01276), Cannot serve directory /var/www/project/:
<p>I am trying to deploy a Django web app on a newly installed centos7 server.
for this i am using apache2.4 with mod_wsgi.</p>
<p>i am stuck at serving the static files and because i am new to this, this is so confusing to me.</p>
<p>here is my configuration files if you can help me with this please.</p>
<h3>/etc/httpd/conf/httpd.conf:</h3>
<p>(i removed everything i am not using here and removed the commented lines)</p>
<pre><code>Listen 80
Include conf.modules.d/*.conf
User apache
Group apache
ServerAdmin admin@serv.com
&lt;Files &quot;.ht*&quot;&gt;
    Require all denied
&lt;/Files&gt;
ErrorLog &quot;logs/error_log&quot;
LogLevel info

&lt;IfModule log_config_module&gt;
    LogFormat &quot;%h %l %u %t \&quot;%r\&quot; %&gt;s %b \&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot;&quot; combined
    LogFormat &quot;%h %l %u %t \&quot;%r\&quot; %&gt;s %b&quot; common
    &lt;IfModule logio_module&gt;
      LogFormat &quot;%h %l %u %t \&quot;%r\&quot; %&gt;s %b \&quot;%{Referer}i\&quot; \&quot;%{User-Agent}i\&quot; %I %O&quot; combinedio
    &lt;/IfModule&gt;
    CustomLog &quot;logs/access_log&quot; combined
&lt;/IfModule&gt;
&lt;IfModule mime_module&gt;
    TypesConfig /etc/mime.types
    AddType application/x-compress .Z
    AddType application/x-gzip .gz .tgz
    AddType text/html .shtml
    AddOutputFilter INCLUDES .shtml
&lt;/IfModule&gt;
AddDefaultCharset UTF-8

&lt;IfModule mime_magic_module&gt;
    MIMEMagicFile conf/magic
&lt;/IfModule&gt;
EnableSendfile on
IncludeOptional sites-enabled/*.conf
LoadModule wsgi_module modules/mod_wsgi.so
</code></pre>
<p>in my sites-enabled folder, i have only one config file for my project</p>
<h3>/etc/httpd/sites-enabled/project.conf:</h3>
<pre><code>Alias /favicon.ico /var/www/cvctools/staticfiles/templates/images/favicon.ico
Alias /static/ /var/www/cvctools/staticfiles/
&lt;VirtualHost *:80&gt;
    DocumentRoot /var/www/cvctools
    ServerName proj.ma
    ServerAlias www.proj.ma
    ServerAdmin admin@proj.ma

    &lt;Directory /var/www/cvctools/staticfiles&gt;
        AllowOverride None
        Require all granted
    &lt;/Directory&gt;

    &lt;IfModule wsgi_module&gt;
        WSGIScriptAlias / /var/www/cvctools/CapValue/wsgi.py
        WSGIScriptReloading On
        WSGIDaemonProcess CapValue processes=1 threads=1 maximum-requests=5000 display-name=my-wsgi
        WSGIProcessGroup CapValue
        WSGIPythonPath /var/www/cvctools
        &lt;Directory /var/www/cvctools/CapValue&gt;
            &lt;Files wsgi.py&gt;
                Require all granted
            &lt;/Files&gt;
        &lt;/Directory&gt;
    &lt;/IfModule&gt;
&lt;/VirtualHost&gt;
</code></pre>
<p>in my project folder located at /var/www/cvctools i have this..</p>
<p>./CapValue/wsgi.py:</p>
<pre><code>import django.core.handlers.wsgi
import os,sys

sys.path.append('/vat/www/cvctools')
os.environ.setdefault(&quot;DJANGO_SETTINGS_MODULE&quot;, &quot;CapValue.settings&quot;)
application = django.core.handlers.wsgi.WSGIHandler()
</code></pre>
<p>my staticfiles settings in ./CapValue/settings.py:</p>
<pre><code>PROJECT_ROOT = os.path.dirname(os.path.abspath(__file__))
STATIC_ROOT = os.path.join(os.getcwd(), 'staticfiles')
STATIC_URL = '/static/'
STATICFILES_DIRS = (os.path.join(PROJECT_ROOT, 'static'),)
STATICFILES_FINDERS = (
    'django.contrib.staticfiles.finders.FileSystemFinder',
    'django.contrib.staticfiles.finders.AppDirectoriesFinder',
    # 'compressor.finders.CompressorFinder',
)
STATICFILES_STORAGE = 'whitenoise.django.GzipManifestStaticFilesStorage'
TEMPLATES = [
    {
        'BACKEND' : 'django.template.backends.django.DjangoTemplates',
        'DIRS'    : [os.path.join(STATIC_ROOT, 'templates'), ],
        'APP_DIRS': True,
        'OPTIONS' : {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]
</code></pre>
<p>./CapValue/views.py:</p>
<pre><code>from django.views.decorators.csrf import ensure_csrf_cookie
from django.views.generic.base import TemplateView
from django.utils.decorators import method_decorator


class IndexView(TemplateView):
    template_name = 'index.html'

    @method_decorator(ensure_csrf_cookie)
    def dispatch(self, *args, **kwargs):
        return super(IndexView, self).dispatch(*args, **kwargs)
</code></pre>
<p>./CapValue/urls.py:</p>
<pre><code>#imports...
urlpatterns = [
    #...
    url('^.*$', IndexView.as_view(), name='index')
]
</code></pre>
<p>and after running manage.py collectstatic, in my project directory i have staticfiles folder with this contents:</p>
<p>/var/www/cvctools/staticfiles/ :</p>
<pre><code>drwxr-xr-x.  6 admin admin    47 Mar  4 22:36 admin
drwxr-xr-x.  2 admin admin  4096 Mar  4 22:36 css
drwxr-xr-x.  5 admin admin    35 Mar  4 22:36 django_extensions
-rwxr-xr-x.  1 admin admin     0 Mar  4 22:36 human.d41d8cd98f00.txt
-rwxr-xr-x.  1 admin admin     0 Mar  4 22:36 human.txt
drwxr-xr-x.  2 admin admin  4096 Mar  4 22:36 images
drwxr-xr-x. 12 admin admin  4096 Mar  4 22:36 javascript
drwxr-xr-x.  2 admin admin  4096 Mar  4 22:36 notifications
drwxr-xr-x.  6 admin admin    47 Mar  4 22:36 rest_framework
-rwxr-xr-x.  1 admin admin 12925 Mar  4 22:36 staticfiles.json
drwxr-xr-x.  6 admin admin  4096 Mar  4 22:36 templates
</code></pre>
<p>but when i'm trying to access the application, in my apache log i get this error:</p>
<pre><code> [autoindex:error] [pid 3150] [client 192.168.0.126:57623] AH01276: Cannot serve directory /var/www/cvctools/: No matching DirectoryIndex (index.html) found, and server-generated directory index forbidden by Options directive
</code></pre>
<p>what exactly i am doing wrong ?</p>
<h1>Edit</h1>
<p>apparently it have something to do with mod_wsgi, beacause i changed my DcumentRoot to /var/www/cvctools/staticfiles/templates
then i was able to see my index page, but it was like this:</p>
<pre><code>{% load staticfiles %} {% include 'stylesheets.html' %}
{% include 'navbar.html' %}
{% include 'menu.html' %}
{#
#} {# {% include 'breadcrumb.html' %}#} {#
#}
{% include 'footer.html' %}
{% include 'javascripts.html' %} 
</code></pre>
<p>it is not picking my template tags !</p>