0

I'm trying to configure Apache with Django. Everything is working except the admin panel. It's static files are not loading. The documentation talks about different ways of doing it but none are working for me.

Here is my 0000-default.conf:

<VirtualHost *:80>
    # The ServerName directive sets the request scheme, hostname and port that
    # the server uses to identify itself. This is used when creating
    # redirection URLs. In the context of virtual hosts, the ServerName
    # specifies what hostname must appear in the request's Host: header to
    # match this virtual host. For the default virtual host (this file) this
    # value is not decisive as it is used as a last resort host regardless.
    # However, you must set it for any further virtual host explicitly.
    #ServerName www.example.com

    ServerAdmin maahd@meddy.co
    DocumentRoot /var/www/html
    <Directory />
        Options FollowSymLinks
        AllowOverride None
    </Directory>
    <Directory /var/www/html>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride None
        Order allow,deny
        allow from all
    </Directory>

    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
        AllowOverride None
        Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
        Order allow,deny
        Allow from all
    </Directory>

    # Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
    # error, crit, alert, emerg.
    # It is also possible to configure the loglevel for particular
    # modules, e.g.
    #LogLevel info ssl:warn

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

    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
        Options Indexes MultiViews FollowSymLinks
        AllowOverride None
        Order deny,allow
        Deny from all
        Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>

Alias /static /var/www/html/sp-django-master/meddy1/static        

    # For most configuration files from conf-available/, which are
    # enabled or disabled at a global level, it is possible to
    # include a line for only one particular virtual host. For example the
    # following line enables the CGI configuration for this host only
    # after it has been globally disabled with "a2disconf".
    #Include conf-available/serve-cgi-bin.conf
</VirtualHost>
include sites-available/meddy.co.conf
# vim: syntax=apache ts=4 sw=4 sts=4 sr noet

Here is my meddy.co.conf where meddy.co is my website:

<VirtualHost *:80>
        ServerName ec2-54-254-141-40.ap-southeast-1.compute.amazonaws.com
        ServerAlias www.ec2-54-254-141-40.ap-southeast-1.compute.amazonaws.com

    WSGIScriptAlias / /var/www/html/sp-django-master/meddy.wsgi

    DocumentRoot /var/www/html/sp-django-master

    #Alias /static /var/www/html/sp-django-master/meddy1/static

    <Location "/static/">
            Options -Indexes
        </Location>

    #AliasMatch ^/([^/]*\.css) /var/www/html/sp-django-master/meddy1/static/meddy1/css/$1

    AliasMatch ^/([^/meddy1]*\.css) /var/www/html/sp-django-master/meddy1/static/meddy1/css/$1
    AliasMatch ^/([^/admin]*\.css) /var/www/html/sp-django-master/static/admin/css/$1   

    Alias /static/ /var/www/html/sp-django-master/meddy1/static/

    <Directory /var/www/html/sp-django-master/meddy1/static>
    Require all granted
    </Directory>

    <Directory /var/www/html/sp-django-master/mysite>
    <Files wsgi.py>
    Require all granted
    </Files>
    </Directory>

    Alias /media/ /var/www/html/sp-django-master/uploads/

        <Directory /var/www/html/sp-django-master/uploads>
        Require all granted
        </Directory>

    Alias /static/admin/ /var/www/html/sp-django-master/static/admin/

</VirtualHost>

Any help would be appreciated.

maahd
  • 121
  • 6
  • I assume you have ran `collectstatic` and you see the files have been copied to `/var/www/html/sp-django-master/meddy1/static`? Have you checked the permissions on these files (check if a temporary `chmod 777` fixes things to check this). What do you have in your Django settings for `STATIC_ROOT`? – fpghost Jul 01 '14 at 12:39
  • figured it out and posted answer below. – maahd Jul 01 '14 at 13:44

1 Answers1

0

Figured it out. You don't need the second last line: Alias /static/admin/ /var/www/html/sp-django-master/static/admin/ since it forces django to look for static files in another folder when django should be looking in the static folder in the app root. So just use Alias /static/ /var/www/html/sp-django-master/meddy1/static/. Since I was using collectstatic, I didn't have to distinguish between static/admin/ and static/

maahd
  • 121
  • 6