1

So, i'm trying to learn django as well as trying to make an app with Angular and Django REST backend on Apache server via mod_wsgi. Currently, i got a problem with static files. Everyhing is ok when app runs with Django tools on 127.0.0.1:8000, but when i load it via Apache - i'm missing statics, so output looks very raw:

enter image description here

I tried to collect statics with manage.py collectstatics, tried to define a dir with statics in python dirs - got nothing:

STATIC_URL = '/static/'

STATIC_ROOT = os.path.join(BASE_DIR, 'DjangoApp/static/')

STATICFILES_DIRS = [
    'C:/Users/<user>/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static',
]

Apache virtual host settings:

<VirtualHost 127.0.0.1:8081>
    ##ServerAdmin webmaster@dummy-host.example.com
    WSGIScriptAlias / "D:/genesi5/Coding/www/django/wsgi_handler.wsgi"
    DocumentRoot "D:/genesi5/Coding/www/django"
    ServerName DjangoApp
    ServerAlias DjangoApp
    ErrorLog "logs/myapp/error.log"
    CustomLog "logs/myapp/access.log" common
    <Directory "D:/genesi5/Coding/www/django">
        AllowOverride All
        Require all Granted
    </Directory>
</VirtualHost>

httpd.conf:

LoadModule wsgi_module "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/lib/site-packages/mod_wsgi/server/mod_wsgi.cp36-win32.pyd"

<IfModule wsgi_module>
    LoadFile "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/python36.dll"
    WSGIPythonHome "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32"
    WSGIPassAuthorization On
</IfModule>

Can you suggest a solution?

genesi5
  • 455
  • 3
  • 17

2 Answers2

1

So, i had to add extra alias in virtualhost settings, and athe moment it's kinda works:

<VirtualHost 127.0.0.1:8081>
    ##ServerAdmin webmaster@dummy-host.example.com
    WSGIScriptAlias / "D:/genesi5/Coding/www/django/wsgi_handler.wsgi"
    DocumentRoot "D:/genesi5/Coding/www/django"
    ServerName DjangoApp
    ServerAlias DjangoApp
    ErrorLog "logs/myapp/error.log"
    CustomLog "logs/myapp/access.log" common
    Alias /static "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static"
    <Directory "C:/Users/Genesi5/AppData/Local/Programs/Python/Python36-32/Lib/site-packages/rest_framework/static">
        Require all Granted
    </Directory>
    <Directory "D:/genesi5/Coding/www/django">
        AllowOverride All
        Require all Granted
    </Directory>
</VirtualHost>
genesi5
  • 455
  • 3
  • 17
1

You have to declare lots of things in Apache2.conf in order to use mod_wsgi

WSGIScriptAlias / /path_to_wsgi.py
WSGIPythonPath /path_to_your_project
Alias /static/ /path_to_your_static_directory

<Directory /path_to_your_static_directory>
        Require all granted
</Directory>

<Directory /path_to_your_project_directory>
        <Files wsgi.py>
                #Options Indexes FollowSymLinks
                #Require all granted
                #SetEnvIfNoCase Host .+ VALID_HOST
                Order deny,allow
                Allow from all
                #Allow from env=VALID_HOST
        </Files>
</Directory>

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

<Directory /usr/share>
       AllowOverride None
       Require all granted
</Directory>

<Directory /var/www/>
       Options Indexes FollowSymLinks
       AllowOverride None
       Require all granted
</Directory>

<Directory /srv/>
       Options Indexes FollowSymLinks
       AllowOverride None
       Require all granted
</Directory>

It's an example with Linux, but it's the same thing with Windows ;)

Essex
  • 6,042
  • 11
  • 67
  • 139